33using System . Linq ;
44using System . Net ;
55using System . Net . Http ;
6- using System . Net . Security ;
76using System . Security . Authentication ;
8- using System . Security . Cryptography . X509Certificates ;
97
108namespace 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