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

fix: automatic decompression of response content #303

Merged
merged 3 commits into from
Jul 23, 2024
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
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 @@ -65,7 +65,7 @@
/// Creates a default set of middleware to be used by the <see cref="HttpClient"/>.
/// </summary>
/// <returns>A list of the default handlers used by the client.</returns>
public static IList<DelegatingHandler> CreateDefaultHandlers(IRequestOption[]? optionsForHandlers = null)

Check warning on line 68 in src/http/httpClient/KiotaClientFactory.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 20 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 68 in src/http/httpClient/KiotaClientFactory.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 20 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 68 in src/http/httpClient/KiotaClientFactory.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 20 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 68 in src/http/httpClient/KiotaClientFactory.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 20 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 68 in src/http/httpClient/KiotaClientFactory.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 20 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
optionsForHandlers ??= Array.Empty<IRequestOption>();

Expand Down Expand Up @@ -165,11 +165,11 @@
// 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 @@
/// <summary>
/// A <see cref="DelegatingHandler"/> implementation that handles compression.
/// </summary>
[Obsolete("kiota clients now rely on the HttpClientHandler to handle decompression")]

Check warning on line 19 in src/http/httpClient/Middleware/CompressionHandler.cs

View workflow job for this annotation

GitHub Actions / Build

Do not forget to remove this deprecated code someday. (https://rules.sonarsource.com/csharp/RSPEC-1133)

Check warning on line 19 in src/http/httpClient/Middleware/CompressionHandler.cs

View workflow job for this annotation

GitHub Actions / Build

Do not forget to remove this deprecated code someday. (https://rules.sonarsource.com/csharp/RSPEC-1133)

Check warning on line 19 in src/http/httpClient/Middleware/CompressionHandler.cs

View workflow job for this annotation

GitHub Actions / Build

Do not forget to remove this deprecated code someday. (https://rules.sonarsource.com/csharp/RSPEC-1133)

Check warning on line 19 in src/http/httpClient/Middleware/CompressionHandler.cs

View workflow job for this annotation

GitHub Actions / Build

Do not forget to remove this deprecated code someday. (https://rules.sonarsource.com/csharp/RSPEC-1133)

Check warning on line 19 in src/http/httpClient/Middleware/CompressionHandler.cs

View workflow job for this annotation

GitHub Actions / Build

Do not forget to remove this deprecated code someday. (https://rules.sonarsource.com/csharp/RSPEC-1133)
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
Loading