Skip to content

Commit 4a9af01

Browse files
committed
Use SocketsHttpHandler on .NET Core
1 parent d4a6cd4 commit 4a9af01

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
using System.Linq;
44
using System.Net;
55
using System.Net.Http;
6-
using System.Net.Security;
76
using System.Security.Authentication;
8-
using System.Security.Cryptography.X509Certificates;
97

108
namespace LibGit2Sharp.Core
119
{
@@ -49,7 +47,12 @@ private class ManagedHttpSmartSubtransportStream : SmartSubtransportStream
4947
{
5048
private static int MAX_REDIRECTS = 7;
5149

52-
private static readonly HttpClientHandler httpClientHandler;
50+
#if NETCOREAPP
51+
private static readonly SocketsHttpHandler httpHandler;
52+
#else
53+
private static readonly HttpClientHandler httpHandler;
54+
#endif
55+
5356
private static readonly CredentialCache credentialCache;
5457

5558
private MemoryStream postBuffer = new MemoryStream();
@@ -58,14 +61,18 @@ private class ManagedHttpSmartSubtransportStream : SmartSubtransportStream
5861

5962
static ManagedHttpSmartSubtransportStream()
6063
{
61-
httpClientHandler = new HttpClientHandler();
62-
63-
httpClientHandler.SslProtocols |= SslProtocols.Tls12;
64+
#if NETCOREAPP
65+
httpHandler = new SocketsHttpHandler();
66+
httpHandler.PooledConnectionLifetime = TimeSpan.FromMinutes(5);
67+
#else
68+
httpHandler = new HttpClientHandler();
69+
httpHandler.SslProtocols |= SslProtocols.Tls12;
70+
#endif
6471

65-
httpClientHandler.AllowAutoRedirect = false;
72+
httpHandler.AllowAutoRedirect = false;
6673

6774
credentialCache = new CredentialCache();
68-
httpClientHandler.Credentials = credentialCache;
75+
httpHandler.Credentials = credentialCache;
6976
}
7077

7178
public ManagedHttpSmartSubtransportStream(ManagedHttpSmartSubtransport parent, string endpointUrl, bool isPost, string contentType)
@@ -150,7 +157,7 @@ private HttpResponseMessage GetResponseWithRedirects()
150157

151158
for (retries = 0; ; retries++)
152159
{
153-
using (var httpClient = CreateHttpClient(httpClientHandler))
160+
using (var httpClient = CreateHttpClient(httpHandler))
154161
{
155162
var request = CreateRequest(url, IsPost);
156163

0 commit comments

Comments
 (0)