Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DecompressionEnabled property and wire up changing HttpClientHandler behavior #4745

Merged
merged 1 commit into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ internal HttpChannelFactory(HttpTransportBindingElement bindingElement, BindingC
}

AuthenticationScheme = bindingElement.AuthenticationScheme;
DecompressionEnabled = bindingElement.DecompressionEnabled;
MaxBufferSize = bindingElement.MaxBufferSize;
TransferMode = bindingElement.TransferMode;
_keepAliveEnabled = bindingElement.KeepAliveEnabled;
Expand Down Expand Up @@ -142,6 +143,8 @@ internal HttpChannelFactory(HttpTransportBindingElement bindingElement, BindingC

public AuthenticationSchemes AuthenticationScheme { get; }

public bool DecompressionEnabled { get; }

public virtual bool IsChannelBindingSupportEnabled
{
get
Expand Down Expand Up @@ -283,7 +286,14 @@ internal async Task<HttpClient> GetHttpClientAsync(EndpointAddress to, Uri via,
if (!foundHttpClient)
{
var clientHandler = GetHttpClientHandler(to, clientCertificateToken);
clientHandler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
if (DecompressionEnabled)
{
clientHandler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
}
else
{
clientHandler.AutomaticDecompression = DecompressionMethods.None;
}

if (clientHandler.SupportsProxy)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace System.ServiceModel.Channels
public class HttpTransportBindingElement
: TransportBindingElement
{
private bool _decompressionEnabled;
private HostNameComparisonMode _hostNameComparisonMode;
private bool _inheritBaseAddressSettings;
private int _maxBufferSize;
Expand All @@ -38,7 +37,7 @@ public HttpTransportBindingElement()
AllowCookies = HttpTransportDefaults.AllowCookies;
AuthenticationScheme = HttpTransportDefaults.AuthenticationScheme;
BypassProxyOnLocal = HttpTransportDefaults.BypassProxyOnLocal;
_decompressionEnabled = HttpTransportDefaults.DecompressionEnabled;
DecompressionEnabled = HttpTransportDefaults.DecompressionEnabled;
_hostNameComparisonMode = HttpTransportDefaults.HostNameComparisonMode;
KeepAliveEnabled = HttpTransportDefaults.KeepAliveEnabled;
_maxBufferSize = TransportDefaults.MaxBufferSize;
Expand All @@ -61,7 +60,7 @@ protected HttpTransportBindingElement(HttpTransportBindingElement elementToBeClo
AllowCookies = elementToBeCloned.AllowCookies;
AuthenticationScheme = elementToBeCloned.AuthenticationScheme;
BypassProxyOnLocal = elementToBeCloned.BypassProxyOnLocal;
_decompressionEnabled = elementToBeCloned._decompressionEnabled;
DecompressionEnabled = elementToBeCloned.DecompressionEnabled;
_hostNameComparisonMode = elementToBeCloned._hostNameComparisonMode;
_inheritBaseAddressSettings = elementToBeCloned.InheritBaseAddressSettings;
KeepAliveEnabled = elementToBeCloned.KeepAliveEnabled;
Expand Down Expand Up @@ -92,17 +91,7 @@ protected HttpTransportBindingElement(HttpTransportBindingElement elementToBeClo
public bool BypassProxyOnLocal { get; set; }

[DefaultValue(HttpTransportDefaults.DecompressionEnabled)]
public bool DecompressionEnabled
{
get
{
return _decompressionEnabled;
}
set
{
_decompressionEnabled = value;
}
}
public bool DecompressionEnabled { get; set; }

[DefaultValue(HttpTransportDefaults.HostNameComparisonMode)]
public HostNameComparisonMode HostNameComparisonMode
Expand Down Expand Up @@ -497,7 +486,7 @@ internal override bool IsMatch(BindingElement b)
return false;
}

if (_decompressionEnabled != http._decompressionEnabled)
if (DecompressionEnabled != http.DecompressionEnabled)
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ internal static class HttpTransportDefaults
internal const bool DecompressionEnabled = true;
internal const HostNameComparisonMode HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard;
internal const bool KeepAliveEnabled = true;
internal const IWebProxy Proxy = null;
internal const IWebProxy Proxy = null;
internal const Uri ProxyAddress = null;
internal const AuthenticationSchemes ProxyAuthenticationScheme = AuthenticationSchemes.Anonymous;
internal const string Realm = "";
Expand Down
8 changes: 5 additions & 3 deletions src/System.ServiceModel.Http/ref/System.ServiceModel.Http.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public NetHttpBinding(string configurationName) { }
[System.ComponentModel.DefaultValueAttribute((System.ServiceModel.NetHttpMessageEncoding)(0))]
public System.ServiceModel.NetHttpMessageEncoding MessageEncoding { get { return default; } set { } }
public System.ServiceModel.BasicHttpSecurity Security { get { return default; } set { } }
public System.ServiceModel.OptionalReliableSession ReliableSession { get; set; }
public System.ServiceModel.OptionalReliableSession ReliableSession { get { return default; } set { } }
public System.ServiceModel.Channels.WebSocketTransportSettings WebSocketSettings { get { return default; } }
public override System.ServiceModel.Channels.IChannelFactory<TChannel> BuildChannelFactory<TChannel>(System.ServiceModel.Channels.BindingParameterCollection parameters) { return default; }
public override System.ServiceModel.Channels.BindingElementCollection CreateBindingElements() { return default; }
Expand All @@ -136,7 +136,7 @@ public NetHttpsBinding(System.ServiceModel.BasicHttpsSecurityMode securityMode,
[System.ComponentModel.DefaultValueAttribute((System.ServiceModel.NetHttpMessageEncoding)(0))]
public System.ServiceModel.NetHttpMessageEncoding MessageEncoding { get { return default; } set { } }
public System.ServiceModel.BasicHttpsSecurity Security { get { return default; } set { } }
public System.ServiceModel.OptionalReliableSession ReliableSession { get; set; }
public System.ServiceModel.OptionalReliableSession ReliableSession { get { return default; } set { } }
public System.ServiceModel.Channels.WebSocketTransportSettings WebSocketSettings { get { return default; } }
public override System.ServiceModel.Channels.IChannelFactory<TChannel> BuildChannelFactory<TChannel>(System.ServiceModel.Channels.BindingParameterCollection parameters) { return default; }
public override System.ServiceModel.Channels.BindingElementCollection CreateBindingElements() { return default; }
Expand Down Expand Up @@ -255,7 +255,9 @@ protected HttpTransportBindingElement(System.ServiceModel.Channels.HttpTransport
public System.Net.AuthenticationSchemes AuthenticationScheme { get { return default; } set { } }
[System.ComponentModel.DefaultValue(false)]
public bool BypassProxyOnLocal { get { return default; } set { } }
public System.Security.Authentication.ExtendedProtection.ExtendedProtectionPolicy ExtendedProtectionPolicy { get; set; }
[System.ComponentModel.DefaultValue(true)]
public bool DecompressionEnabled { get { return default; } set { } }
public System.Security.Authentication.ExtendedProtection.ExtendedProtectionPolicy ExtendedProtectionPolicy { get { return default; } set { } }
[System.ComponentModel.DefaultValueAttribute(65536)]
public int MaxBufferSize { get { return default; } set { } }
[System.ComponentModel.DefaultValue(null)]
Expand Down