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

Commit a1aa04c

Browse files
authored
Merge pull request #251 from ghelyar/main
Use SocketsHttpHandler and EnableMultipleHttp2Connections as default handler
2 parents 41b6ae2 + 285203c commit a1aa04c

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.4.1] - 2024-05-07
11+
12+
## Changed
13+
14+
- Use `SocketsHttpHandler` with `EnableMultipleHttp2Connections` as default HTTP message handler.
15+
1016
## [1.4.0]
1117

1218
## Added

Microsoft.Kiota.Http.HttpClientLibrary.Tests/KiotaClientFactoryTests.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ public void ChainHandlersCollectionAndGetFirstLinkWithMultipleHandlersSetsFinalH
6868
Assert.IsType<HttpClientHandler>(innerHandler.InnerHandler);
6969
}
7070

71+
[Fact]
72+
public void GetDefaultHttpMessageHandlerEnablesMultipleHttp2Connections()
73+
{
74+
// Act
75+
var defaultHandler = KiotaClientFactory.GetDefaultHttpMessageHandler();
76+
// Assert
77+
Assert.NotNull(defaultHandler);
78+
#if NETFRAMEWORK
79+
Assert.IsType<WinHttpHandler>(defaultHandler);
80+
Assert.True(((WinHttpHandler)defaultHandler).EnableMultipleHttp2Connections);
81+
#else
82+
Assert.IsType<SocketsHttpHandler>(defaultHandler);
83+
Assert.True(((SocketsHttpHandler)defaultHandler).EnableMultipleHttp2Connections);
84+
#endif
85+
}
86+
7187
[Fact]
7288
public void GetDefaultHttpMessageHandlerSetsUpProxy()
7389
{
@@ -81,10 +97,9 @@ public void GetDefaultHttpMessageHandlerSetsUpProxy()
8197
Assert.IsType<WinHttpHandler>(defaultHandler);
8298
Assert.Equal(proxy, ((WinHttpHandler)defaultHandler).Proxy);
8399
#else
84-
Assert.IsType<HttpClientHandler>(defaultHandler);
85-
Assert.Equal(proxy, ((HttpClientHandler)defaultHandler).Proxy);
100+
Assert.IsType<SocketsHttpHandler>(defaultHandler);
101+
Assert.Equal(proxy, ((SocketsHttpHandler)defaultHandler).Proxy);
86102
#endif
87-
88103
}
89104

90105
[Fact]

src/KiotaClientFactory.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ public static HttpMessageHandler GetDefaultHttpMessageHandler(IWebProxy? proxy =
104104
// If custom proxy is passed, the WindowsProxyUsePolicy will need updating
105105
// https://github.com/dotnet/runtime/blob/main/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs#L575
106106
var proxyPolicy = proxy != null ? WindowsProxyUsePolicy.UseCustomProxy : WindowsProxyUsePolicy.UseWinHttpProxy;
107-
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 };
107+
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 };
108+
#elif NET5_0_OR_GREATER
109+
return new SocketsHttpHandler { Proxy = proxy, AllowAutoRedirect = false, EnableMultipleHttp2Connections = true };
108110
#else
109111
return new HttpClientHandler { Proxy = proxy, AllowAutoRedirect = false };
110112
#endif

src/Microsoft.Kiota.Http.HttpClientLibrary.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageProjectUrl>https://aka.ms/kiota/docs</PackageProjectUrl>
1616
<EmbedUntrackedSources>true</EmbedUntrackedSources>
1717
<Deterministic>true</Deterministic>
18-
<VersionPrefix>1.4.0</VersionPrefix>
18+
<VersionPrefix>1.4.1</VersionPrefix>
1919
<VersionSuffix></VersionSuffix>
2020
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
2121
<!-- Enable this line once we go live to prevent breaking changes -->

0 commit comments

Comments
 (0)