Skip to content

Commit 1c141d4

Browse files
committed
Fix support for using proxies with HTTP transport
1 parent 761fa97 commit 1c141d4

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/System.Private.ServiceModel/src/System/ServiceModel/Channels/HttpChannelFactory.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ internal class HttpChannelFactory<TChannel>
4747
private TransferMode _transferMode;
4848
private ISecurityCapabilities _securityCapabilities;
4949
private WebSocketTransportSettings _webSocketSettings;
50-
private bool _useDefaultWebProxy;
5150
private Lazy<string> _webSocketSoapContentType;
5251
private SHA512 _hashAlgorithm;
5352
private bool _keepAliveEnabled;
@@ -299,14 +298,19 @@ internal async Task<HttpClient> GetHttpClientAsync(EndpointAddress to,
299298
var clientHandler = GetHttpClientHandler(to, clientCertificateToken);
300299
clientHandler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
301300

302-
if (_proxy != null)
303-
{
304-
clientHandler.Proxy = _proxy;
305-
}
306-
else if (_proxyFactory != null)
301+
if (clientHandler.SupportsProxy)
307302
{
308-
clientHandler.Proxy = await _proxyFactory.CreateWebProxyAsync(authenticationLevelWrapper.Value,
309-
impersonationLevelWrapper.Value, proxyTokenProvider, cancellationToken);
303+
if (_proxy != null)
304+
{
305+
clientHandler.Proxy = _proxy;
306+
clientHandler.UseProxy = true;
307+
}
308+
else if (_proxyFactory != null)
309+
{
310+
clientHandler.Proxy = await _proxyFactory.CreateWebProxyAsync(authenticationLevelWrapper.Value,
311+
impersonationLevelWrapper.Value, proxyTokenProvider, cancellationToken);
312+
clientHandler.UseProxy = true;
313+
}
310314
}
311315

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

318322
clientHandler.PreAuthenticate = true;
319-
if (clientHandler.SupportsProxy)
320-
{
321-
clientHandler.UseProxy = _useDefaultWebProxy;
322-
}
323323

324324
clientHandler.UseDefaultCredentials = false;
325325
if (credential == CredentialCache.DefaultCredentials)

src/System.Private.ServiceModel/src/System/ServiceModel/Channels/HttpTransportBindingElement.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public HttpTransportBindingElement()
4949
_maxBufferSize = TransportDefaults.MaxBufferSize;
5050
_maxPendingAccepts = HttpTransportDefaults.DefaultMaxPendingAccepts;
5151
_method = string.Empty;
52+
_proxyAuthenticationScheme = HttpTransportDefaults.ProxyAuthenticationScheme;
53+
_proxyAddress = HttpTransportDefaults.ProxyAddress;
5254
_realm = HttpTransportDefaults.Realm;
5355
_requestInitializationTimeout = HttpTransportDefaults.RequestInitializationTimeout;
5456
_transferMode = HttpTransportDefaults.TransferMode;
@@ -71,14 +73,16 @@ protected HttpTransportBindingElement(HttpTransportBindingElement elementToBeClo
7173
_maxBufferSizeInitialized = elementToBeCloned._maxBufferSizeInitialized;
7274
_maxPendingAccepts = elementToBeCloned._maxPendingAccepts;
7375
_method = elementToBeCloned._method;
76+
_proxyAddress = elementToBeCloned._proxyAddress;
77+
_proxyAuthenticationScheme = elementToBeCloned._proxyAuthenticationScheme;
7478
_realm = elementToBeCloned._realm;
7579
_requestInitializationTimeout = elementToBeCloned._requestInitializationTimeout;
7680
_transferMode = elementToBeCloned._transferMode;
7781
_unsafeConnectionNtlmAuthentication = elementToBeCloned._unsafeConnectionNtlmAuthentication;
7882
_useDefaultWebProxy = elementToBeCloned._useDefaultWebProxy;
7983
_webSocketSettings = elementToBeCloned._webSocketSettings.Clone();
8084
_extendedProtectionPolicy = elementToBeCloned.ExtendedProtectionPolicy;
81-
this.MessageHandlerFactory = elementToBeCloned.MessageHandlerFactory;
85+
MessageHandlerFactory = elementToBeCloned.MessageHandlerFactory;
8286
}
8387

8488
[DefaultValue(HttpTransportDefaults.AllowCookies)]

0 commit comments

Comments
 (0)