From 8913e95b4001c06038adb23d00a8a98fb0bd0a96 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 22 Jul 2024 10:45:04 -0400 Subject: [PATCH 1/3] fix: automatic decompression of response content Signed-off-by: Vincent Biret --- CHANGELOG.md | 6 +++++- Directory.Build.props | 4 ++-- src/http/httpClient/KiotaClientFactory.cs | 6 +++--- src/http/httpClient/Middleware/CompressionHandler.cs | 1 + 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e77e7fb..85927d47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.9.11] - 2024-07-22 + +- Obsoletes custom decompression handler in favor of native client capabilities. + ## [1.9.10] - 2024-07-18 - Fix DateTime serialization and deserialization @@ -27,4 +31,4 @@ Refer to the following for earlier releases of libraries in the project. 1. [Serialization - JSON](./src/serialization/json/Changelog-old.md) 1. [Serialization - FORM](./src/serialization/form/Changelog-old.md) 1. [Serialization - TEXT](./src/serialization/text/Changelog-old.md) -1. [Serialization - MULTIPART](./src/serialization/multipart/Changelog-old.md) \ No newline at end of file +1. [Serialization - MULTIPART](./src/serialization/multipart/Changelog-old.md) diff --git a/Directory.Build.props b/Directory.Build.props index 6751c2c3..1d7bd68b 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 1.9.10 + 1.9.11 false @@ -17,4 +17,4 @@ false Library - + \ No newline at end of file diff --git a/src/http/httpClient/KiotaClientFactory.cs b/src/http/httpClient/KiotaClientFactory.cs index 8a6957e1..a8bce0b7 100644 --- a/src/http/httpClient/KiotaClientFactory.cs +++ b/src/http/httpClient/KiotaClientFactory.cs @@ -165,11 +165,11 @@ public static HttpMessageHandler GetDefaultHttpMessageHandler(IWebProxy? proxy = // If custom proxy is passed, the WindowsProxyUsePolicy will need updating // https://github.com/dotnet/runtime/blob/main/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs#L575 var proxyPolicy = proxy != null ? WindowsProxyUsePolicy.UseCustomProxy : WindowsProxyUsePolicy.UseWinHttpProxy; - return new WinHttpHandler { Proxy = proxy, AutomaticDecompression = DecompressionMethods.None, WindowsProxyUsePolicy = proxyPolicy, SendTimeout = System.Threading.Timeout.InfiniteTimeSpan, ReceiveDataTimeout = System.Threading.Timeout.InfiniteTimeSpan, ReceiveHeadersTimeout = System.Threading.Timeout.InfiniteTimeSpan, EnableMultipleHttp2Connections = true }; + return new WinHttpHandler { Proxy = proxy, AutomaticDecompression = DecompressionMethods.All, WindowsProxyUsePolicy = proxyPolicy, SendTimeout = System.Threading.Timeout.InfiniteTimeSpan, ReceiveDataTimeout = System.Threading.Timeout.InfiniteTimeSpan, ReceiveHeadersTimeout = System.Threading.Timeout.InfiniteTimeSpan, EnableMultipleHttp2Connections = true }; #elif NET5_0_OR_GREATER - return new SocketsHttpHandler { Proxy = proxy, AllowAutoRedirect = false, EnableMultipleHttp2Connections = true }; + return new SocketsHttpHandler { Proxy = proxy, AllowAutoRedirect = false, EnableMultipleHttp2Connections = true, AutomaticDecompression = DecompressionMethods.All }; #else - return new HttpClientHandler { Proxy = proxy, AllowAutoRedirect = false }; + return new HttpClientHandler { Proxy = proxy, AllowAutoRedirect = false, AutomaticDecompression = DecompressionMethods.All }; #endif } } diff --git a/src/http/httpClient/Middleware/CompressionHandler.cs b/src/http/httpClient/Middleware/CompressionHandler.cs index ee05e2c0..d80270a2 100644 --- a/src/http/httpClient/Middleware/CompressionHandler.cs +++ b/src/http/httpClient/Middleware/CompressionHandler.cs @@ -16,6 +16,7 @@ namespace Microsoft.Kiota.Http.HttpClientLibrary.Middleware /// /// A implementation that handles compression. /// + [Obsolete("kiota clients now rely on the HttpClientHandler to handle decompression")] public class CompressionHandler : DelegatingHandler { internal const string GZip = "gzip"; From 7f119498f7b41e7787d1b6ea554cbb6b906e90f4 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 22 Jul 2024 12:23:59 -0400 Subject: [PATCH 2/3] fix: all is not available in older runtimes Signed-off-by: Vincent Biret --- src/http/httpClient/KiotaClientFactory.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/http/httpClient/KiotaClientFactory.cs b/src/http/httpClient/KiotaClientFactory.cs index a8bce0b7..5a89c01a 100644 --- a/src/http/httpClient/KiotaClientFactory.cs +++ b/src/http/httpClient/KiotaClientFactory.cs @@ -165,11 +165,11 @@ public static HttpMessageHandler GetDefaultHttpMessageHandler(IWebProxy? proxy = // If custom proxy is passed, the WindowsProxyUsePolicy will need updating // https://github.com/dotnet/runtime/blob/main/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs#L575 var proxyPolicy = proxy != null ? WindowsProxyUsePolicy.UseCustomProxy : WindowsProxyUsePolicy.UseWinHttpProxy; - return new WinHttpHandler { Proxy = proxy, AutomaticDecompression = DecompressionMethods.All, WindowsProxyUsePolicy = proxyPolicy, SendTimeout = System.Threading.Timeout.InfiniteTimeSpan, ReceiveDataTimeout = System.Threading.Timeout.InfiniteTimeSpan, ReceiveHeadersTimeout = System.Threading.Timeout.InfiniteTimeSpan, EnableMultipleHttp2Connections = true }; + return new WinHttpHandler { Proxy = proxy, AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, WindowsProxyUsePolicy = proxyPolicy, SendTimeout = System.Threading.Timeout.InfiniteTimeSpan, ReceiveDataTimeout = System.Threading.Timeout.InfiniteTimeSpan, ReceiveHeadersTimeout = System.Threading.Timeout.InfiniteTimeSpan, EnableMultipleHttp2Connections = true }; #elif NET5_0_OR_GREATER return new SocketsHttpHandler { Proxy = proxy, AllowAutoRedirect = false, EnableMultipleHttp2Connections = true, AutomaticDecompression = DecompressionMethods.All }; #else - return new HttpClientHandler { Proxy = proxy, AllowAutoRedirect = false, AutomaticDecompression = DecompressionMethods.All }; + return new HttpClientHandler { Proxy = proxy, AllowAutoRedirect = false, AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }; #endif } } From 4b32a2f79f89d68c8422ebce4a8fb671355a8396 Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Tue, 23 Jul 2024 09:54:36 +0300 Subject: [PATCH 3/3] Suppress warnings in tests --- tests/http/httpClient/KiotaClientFactoryTests.cs | 2 ++ tests/http/httpClient/Middleware/CompressionHandlerTests.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/tests/http/httpClient/KiotaClientFactoryTests.cs b/tests/http/httpClient/KiotaClientFactoryTests.cs index ce914bd3..47d1dd19 100644 --- a/tests/http/httpClient/KiotaClientFactoryTests.cs +++ b/tests/http/httpClient/KiotaClientFactoryTests.cs @@ -132,7 +132,9 @@ public void CreateWithNullOrEmptyHandlersReturnsHttpClient() public void CreateWithCustomMiddlewarePipelineReturnsHttpClient() { var handlers = KiotaClientFactory.CreateDefaultHandlers(); +#pragma warning disable CS0618 // Type or member is obsolete handlers.Add(new CompressionHandler()); +#pragma warning restore CS0618 // Type or member is obsolete var client = KiotaClientFactory.Create(handlers); Assert.IsType(client); } diff --git a/tests/http/httpClient/Middleware/CompressionHandlerTests.cs b/tests/http/httpClient/Middleware/CompressionHandlerTests.cs index cf44023f..61ad60fe 100644 --- a/tests/http/httpClient/Middleware/CompressionHandlerTests.cs +++ b/tests/http/httpClient/Middleware/CompressionHandlerTests.cs @@ -12,6 +12,7 @@ namespace Microsoft.Kiota.Http.HttpClientLibrary.Tests.Middleware { + [Obsolete("kiota clients now rely on the HttpClientHandler to handle decompression")] public class CompressionHandlerTests : IDisposable { private readonly MockRedirectHandler _testHttpMessageHandler;