@@ -106,20 +106,70 @@ await modifyClient(httpClient)
106106
107107 private SocketsHttpHandler GetOrCreateHandler ( HttpClientOptions ? options )
108108 {
109- var key = new HandlerKey ( options ? . PooledConnectionLifetime ? . TotalSeconds ?? 600 , options ? . MaxConnectionsPerServer ?? 40 ,
110- options ? . UseCookieContainer == true ) ;
109+ double connectTimeoutSeconds = options ? . Timeout ? . TotalSeconds ?? 100 ;
110+
111+ var key = new HandlerKey (
112+ LifetimeSeconds : options ? . PooledConnectionLifetime ? . TotalSeconds ?? 600 ,
113+ MaxConnections : options ? . MaxConnectionsPerServer ?? 40 ,
114+ UseCookies : options ? . UseCookieContainer == true ,
115+ ConnectTimeoutSeconds : connectTimeoutSeconds ,
116+ ResponseDrainTimeoutSeconds : options ? . ResponseDrainTimeout ? . TotalSeconds ,
117+ AllowAutoRedirect : options ? . AllowAutoRedirect ,
118+ AutomaticDecompression : ( int ? ) options ? . AutomaticDecompression ,
119+ KeepAlivePingDelaySeconds : options ? . KeepAlivePingDelay ? . TotalSeconds ,
120+ KeepAlivePingTimeoutSeconds : options ? . KeepAlivePingTimeout ? . TotalSeconds ,
121+ KeepAlivePingPolicy : ( int ? ) options ? . KeepAlivePingPolicy ,
122+ UseProxy : options ? . UseProxy ,
123+ ProxyHashCode : options ? . Proxy ? . GetHashCode ( ) ,
124+ MaxResponseDrainSize : options ? . MaxResponseDrainSize ,
125+ MaxResponseHeadersLength : options ? . MaxResponseHeadersLength ,
126+ SslOptionsHashCode : options ? . SslOptions ? . GetHashCode ( ) ) ;
111127
112128 return _handlers . GetOrAdd ( key , _ =>
113129 {
114130 var handler = new SocketsHttpHandler
115131 {
116132 PooledConnectionLifetime = TimeSpan . FromSeconds ( key . LifetimeSeconds ) ,
117- MaxConnectionsPerServer = key . MaxConnections
133+ MaxConnectionsPerServer = key . MaxConnections ,
134+ ConnectTimeout = TimeSpan . FromSeconds ( key . ConnectTimeoutSeconds )
118135 } ;
119136
120137 if ( key . UseCookies )
121138 handler . CookieContainer = new CookieContainer ( ) ;
122139
140+ if ( key . ResponseDrainTimeoutSeconds . HasValue )
141+ handler . ResponseDrainTimeout = TimeSpan . FromSeconds ( key . ResponseDrainTimeoutSeconds . Value ) ;
142+
143+ if ( key . AllowAutoRedirect . HasValue )
144+ handler . AllowAutoRedirect = key . AllowAutoRedirect . Value ;
145+
146+ if ( key . AutomaticDecompression . HasValue )
147+ handler . AutomaticDecompression = ( DecompressionMethods ) key . AutomaticDecompression . Value ;
148+
149+ if ( key . KeepAlivePingDelaySeconds . HasValue )
150+ handler . KeepAlivePingDelay = TimeSpan . FromSeconds ( key . KeepAlivePingDelaySeconds . Value ) ;
151+
152+ if ( key . KeepAlivePingTimeoutSeconds . HasValue )
153+ handler . KeepAlivePingTimeout = TimeSpan . FromSeconds ( key . KeepAlivePingTimeoutSeconds . Value ) ;
154+
155+ if ( key . KeepAlivePingPolicy . HasValue )
156+ handler . KeepAlivePingPolicy = ( HttpKeepAlivePingPolicy ) key . KeepAlivePingPolicy . Value ;
157+
158+ if ( key . UseProxy . HasValue )
159+ handler . UseProxy = key . UseProxy . Value ;
160+
161+ if ( options ? . Proxy != null )
162+ handler . Proxy = options . Proxy ;
163+
164+ if ( key . MaxResponseDrainSize . HasValue )
165+ handler . MaxResponseDrainSize = key . MaxResponseDrainSize . Value ;
166+
167+ if ( key . MaxResponseHeadersLength . HasValue )
168+ handler . MaxResponseHeadersLength = key . MaxResponseHeadersLength . Value ;
169+
170+ if ( options ? . SslOptions != null )
171+ handler . SslOptions = options . SslOptions ;
172+
123173 return handler ;
124174 } ) ;
125175 }
0 commit comments