Skip to content

Commit 094a69b

Browse files
lockwobrbretcope
authored andcommitted
Add support for http basic auth.
1 parent 5c5cda2 commit 094a69b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

BosunReporter/MetricsCollector.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,14 @@ private void PostToBosun(string path, bool gzip, ApiPostWriter postWriter)
594594
if (gzip)
595595
request.Headers["Content-Encoding"] = "gzip";
596596

597+
// support for http://username:password@domain.com, by default this does not work
598+
var userInfo = url.GetComponents(UriComponents.UserInfo, UriFormat.Unescaped);
599+
if (!string.IsNullOrEmpty(userInfo))
600+
{
601+
var auth = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(userInfo));
602+
request.Headers["Authorization"] = auth;
603+
}
604+
597605
try
598606
{
599607
using (var stream = request.GetRequestStream())

0 commit comments

Comments
 (0)