Skip to content

Commit

Permalink
Add support for proxy credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
matteocontrini committed Dec 4, 2019
1 parent 297e999 commit fb871fb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion PlainHttp/HttpClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,17 @@ private HttpClient ProxiedClientFromCache(Uri proxyUri)

protected virtual HttpClient CreateProxiedClient(Uri proxyUrl)
{
WebProxy proxy = new WebProxy(proxyUrl);

if (!string.IsNullOrEmpty(proxyUrl.UserInfo))
{
string[] parts = proxyUrl.UserInfo.Split(':', 2);
proxy.Credentials = new NetworkCredential(parts[0], parts[1]);
}

HttpMessageHandler handler = new SocketsHttpHandler()
{
Proxy = new WebProxy(proxyUrl),
Proxy = proxy,
UseProxy = true,
PooledConnectionLifetime = TimeSpan.FromMinutes(10),
UseCookies = false,
Expand Down

0 comments on commit fb871fb

Please sign in to comment.