Skip to content

Commit

Permalink
Fix support for using proxies with HTTP transport
Browse files Browse the repository at this point in the history
  • Loading branch information
mconnew committed Jan 27, 2018
1 parent 761fa97 commit 1c141d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ internal class HttpChannelFactory<TChannel>
private TransferMode _transferMode;
private ISecurityCapabilities _securityCapabilities;
private WebSocketTransportSettings _webSocketSettings;
private bool _useDefaultWebProxy;
private Lazy<string> _webSocketSoapContentType;
private SHA512 _hashAlgorithm;
private bool _keepAliveEnabled;
Expand Down Expand Up @@ -299,14 +298,19 @@ internal async Task<HttpClient> GetHttpClientAsync(EndpointAddress to,
var clientHandler = GetHttpClientHandler(to, clientCertificateToken);
clientHandler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;

if (_proxy != null)
{
clientHandler.Proxy = _proxy;
}
else if (_proxyFactory != null)
if (clientHandler.SupportsProxy)
{
clientHandler.Proxy = await _proxyFactory.CreateWebProxyAsync(authenticationLevelWrapper.Value,
impersonationLevelWrapper.Value, proxyTokenProvider, cancellationToken);
if (_proxy != null)
{
clientHandler.Proxy = _proxy;
clientHandler.UseProxy = true;
}
else if (_proxyFactory != null)
{
clientHandler.Proxy = await _proxyFactory.CreateWebProxyAsync(authenticationLevelWrapper.Value,
impersonationLevelWrapper.Value, proxyTokenProvider, cancellationToken);
clientHandler.UseProxy = true;
}
}

clientHandler.UseCookies = _allowCookies;
Expand All @@ -316,10 +320,6 @@ internal async Task<HttpClient> GetHttpClientAsync(EndpointAddress to,
}

clientHandler.PreAuthenticate = true;
if (clientHandler.SupportsProxy)
{
clientHandler.UseProxy = _useDefaultWebProxy;
}

clientHandler.UseDefaultCredentials = false;
if (credential == CredentialCache.DefaultCredentials)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public HttpTransportBindingElement()
_maxBufferSize = TransportDefaults.MaxBufferSize;
_maxPendingAccepts = HttpTransportDefaults.DefaultMaxPendingAccepts;
_method = string.Empty;
_proxyAuthenticationScheme = HttpTransportDefaults.ProxyAuthenticationScheme;
_proxyAddress = HttpTransportDefaults.ProxyAddress;
_realm = HttpTransportDefaults.Realm;
_requestInitializationTimeout = HttpTransportDefaults.RequestInitializationTimeout;
_transferMode = HttpTransportDefaults.TransferMode;
Expand All @@ -71,14 +73,16 @@ protected HttpTransportBindingElement(HttpTransportBindingElement elementToBeClo
_maxBufferSizeInitialized = elementToBeCloned._maxBufferSizeInitialized;
_maxPendingAccepts = elementToBeCloned._maxPendingAccepts;
_method = elementToBeCloned._method;
_proxyAddress = elementToBeCloned._proxyAddress;
_proxyAuthenticationScheme = elementToBeCloned._proxyAuthenticationScheme;
_realm = elementToBeCloned._realm;
_requestInitializationTimeout = elementToBeCloned._requestInitializationTimeout;
_transferMode = elementToBeCloned._transferMode;
_unsafeConnectionNtlmAuthentication = elementToBeCloned._unsafeConnectionNtlmAuthentication;
_useDefaultWebProxy = elementToBeCloned._useDefaultWebProxy;
_webSocketSettings = elementToBeCloned._webSocketSettings.Clone();
_extendedProtectionPolicy = elementToBeCloned.ExtendedProtectionPolicy;
this.MessageHandlerFactory = elementToBeCloned.MessageHandlerFactory;
MessageHandlerFactory = elementToBeCloned.MessageHandlerFactory;
}

[DefaultValue(HttpTransportDefaults.AllowCookies)]
Expand Down

0 comments on commit 1c141d4

Please sign in to comment.