From 418713519911f52eed19583bd897c8a0f85c7add Mon Sep 17 00:00:00 2001 From: Matt Connew Date: Fri, 15 Oct 2021 16:30:04 -0700 Subject: [PATCH] Add DecompressionEnabled property and wire up changing HttpClientHandler behavior --- .../Channels/HttpChannelFactory.cs | 12 +++++++++++- .../Channels/HttpTransportBindingElement.cs | 19 ++++--------------- .../Channels/TransportDefaults.cs | 2 +- .../ref/System.ServiceModel.Http.cs | 8 +++++--- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/HttpChannelFactory.cs b/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/HttpChannelFactory.cs index 7675f17be77..aad2018594e 100644 --- a/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/HttpChannelFactory.cs +++ b/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/HttpChannelFactory.cs @@ -96,6 +96,7 @@ internal HttpChannelFactory(HttpTransportBindingElement bindingElement, BindingC } AuthenticationScheme = bindingElement.AuthenticationScheme; + DecompressionEnabled = bindingElement.DecompressionEnabled; MaxBufferSize = bindingElement.MaxBufferSize; TransferMode = bindingElement.TransferMode; _keepAliveEnabled = bindingElement.KeepAliveEnabled; @@ -142,6 +143,8 @@ internal HttpChannelFactory(HttpTransportBindingElement bindingElement, BindingC public AuthenticationSchemes AuthenticationScheme { get; } + public bool DecompressionEnabled { get; } + public virtual bool IsChannelBindingSupportEnabled { get @@ -283,7 +286,14 @@ internal async Task 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) { diff --git a/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/HttpTransportBindingElement.cs b/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/HttpTransportBindingElement.cs index f451c88e7ad..2cc69cbce90 100644 --- a/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/HttpTransportBindingElement.cs +++ b/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/HttpTransportBindingElement.cs @@ -16,7 +16,6 @@ namespace System.ServiceModel.Channels public class HttpTransportBindingElement : TransportBindingElement { - private bool _decompressionEnabled; private HostNameComparisonMode _hostNameComparisonMode; private bool _inheritBaseAddressSettings; private int _maxBufferSize; @@ -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; @@ -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; @@ -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 @@ -497,7 +486,7 @@ internal override bool IsMatch(BindingElement b) return false; } - if (_decompressionEnabled != http._decompressionEnabled) + if (DecompressionEnabled != http.DecompressionEnabled) { return false; } diff --git a/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/TransportDefaults.cs b/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/TransportDefaults.cs index bbd25bb9ded..5b151fe38a6 100644 --- a/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/TransportDefaults.cs +++ b/src/System.Private.ServiceModel/src/System/ServiceModel/Channels/TransportDefaults.cs @@ -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 = ""; diff --git a/src/System.ServiceModel.Http/ref/System.ServiceModel.Http.cs b/src/System.ServiceModel.Http/ref/System.ServiceModel.Http.cs index df21cd55a2a..3806a7dae40 100644 --- a/src/System.ServiceModel.Http/ref/System.ServiceModel.Http.cs +++ b/src/System.ServiceModel.Http/ref/System.ServiceModel.Http.cs @@ -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 BuildChannelFactory(System.ServiceModel.Channels.BindingParameterCollection parameters) { return default; } public override System.ServiceModel.Channels.BindingElementCollection CreateBindingElements() { return default; } @@ -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 BuildChannelFactory(System.ServiceModel.Channels.BindingParameterCollection parameters) { return default; } public override System.ServiceModel.Channels.BindingElementCollection CreateBindingElements() { return default; } @@ -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)]