Skip to content

Commit

Permalink
Merge pull request #303 from microsoft/bugfix/automatic-decompression
Browse files Browse the repository at this point in the history
fix: automatic decompression of response content
  • Loading branch information
baywet authored Jul 23, 2024
2 parents 10b879b + 4b32a2f commit 42ea74e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
1. [Serialization - MULTIPART](./src/serialization/multipart/Changelog-old.md)
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<!-- Common default project properties for ALL projects-->
<PropertyGroup>
<VersionPrefix>1.9.10</VersionPrefix>
<VersionPrefix>1.9.11</VersionPrefix>
<VersionSuffix></VersionSuffix>
<!-- This is overidden in test projects by setting to true-->
<IsTestProject>false</IsTestProject>
Expand All @@ -17,4 +17,4 @@
<IsPackable>false</IsPackable>
<OutputType>Library</OutputType>
</PropertyGroup>
</Project>
</Project>
6 changes: 3 additions & 3 deletions src/http/httpClient/KiotaClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.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 };
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.GZip | DecompressionMethods.Deflate };
#endif
}
}
Expand Down
1 change: 1 addition & 0 deletions src/http/httpClient/Middleware/CompressionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Microsoft.Kiota.Http.HttpClientLibrary.Middleware
/// <summary>
/// A <see cref="DelegatingHandler"/> implementation that handles compression.
/// </summary>
[Obsolete("kiota clients now rely on the HttpClientHandler to handle decompression")]
public class CompressionHandler : DelegatingHandler
{
internal const string GZip = "gzip";
Expand Down
2 changes: 2 additions & 0 deletions tests/http/httpClient/KiotaClientFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpClient>(client);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 42ea74e

Please sign in to comment.