Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #251 from ghelyar/main
Browse files Browse the repository at this point in the history
Use SocketsHttpHandler and EnableMultipleHttp2Connections as default handler
  • Loading branch information
baywet authored May 7, 2024
2 parents 41b6ae2 + 285203c commit a1aa04c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.4.1] - 2024-05-07

## Changed

- Use `SocketsHttpHandler` with `EnableMultipleHttp2Connections` as default HTTP message handler.

## [1.4.0]

## Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ public void ChainHandlersCollectionAndGetFirstLinkWithMultipleHandlersSetsFinalH
Assert.IsType<HttpClientHandler>(innerHandler.InnerHandler);
}

[Fact]
public void GetDefaultHttpMessageHandlerEnablesMultipleHttp2Connections()
{
// Act
var defaultHandler = KiotaClientFactory.GetDefaultHttpMessageHandler();
// Assert
Assert.NotNull(defaultHandler);
#if NETFRAMEWORK
Assert.IsType<WinHttpHandler>(defaultHandler);
Assert.True(((WinHttpHandler)defaultHandler).EnableMultipleHttp2Connections);
#else
Assert.IsType<SocketsHttpHandler>(defaultHandler);
Assert.True(((SocketsHttpHandler)defaultHandler).EnableMultipleHttp2Connections);
#endif
}

[Fact]
public void GetDefaultHttpMessageHandlerSetsUpProxy()
{
Expand All @@ -81,10 +97,9 @@ public void GetDefaultHttpMessageHandlerSetsUpProxy()
Assert.IsType<WinHttpHandler>(defaultHandler);
Assert.Equal(proxy, ((WinHttpHandler)defaultHandler).Proxy);
#else
Assert.IsType<HttpClientHandler>(defaultHandler);
Assert.Equal(proxy, ((HttpClientHandler)defaultHandler).Proxy);
Assert.IsType<SocketsHttpHandler>(defaultHandler);
Assert.Equal(proxy, ((SocketsHttpHandler)defaultHandler).Proxy);
#endif

}

[Fact]
Expand Down
4 changes: 3 additions & 1 deletion src/KiotaClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ 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 };
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 };
#elif NET5_0_OR_GREATER
return new SocketsHttpHandler { Proxy = proxy, AllowAutoRedirect = false, EnableMultipleHttp2Connections = true };
#else
return new HttpClientHandler { Proxy = proxy, AllowAutoRedirect = false };
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Kiota.Http.HttpClientLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageProjectUrl>https://aka.ms/kiota/docs</PackageProjectUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<Deterministic>true</Deterministic>
<VersionPrefix>1.4.0</VersionPrefix>
<VersionPrefix>1.4.1</VersionPrefix>
<VersionSuffix></VersionSuffix>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<!-- Enable this line once we go live to prevent breaking changes -->
Expand Down

0 comments on commit a1aa04c

Please sign in to comment.