@@ -124,12 +124,13 @@ public partial class HtmlWeb
124
124
internal static ConcurrentDictionary < string , HttpClient > SharedHttpClient = new ConcurrentDictionary < string , HttpClient > ( ) ;
125
125
126
126
127
- internal static HttpClient GetSharedHttpClient ( string userAgent )
127
+ internal static HttpClient GetSharedHttpClient ( HtmlWeb web )
128
128
{
129
- return SharedHttpClient . GetOrAdd ( userAgent , x =>
129
+ return SharedHttpClient . GetOrAdd ( web . UserAgent , x =>
130
130
{
131
131
var client = new HttpClient ( ) ;
132
- client . DefaultRequestHeaders . Add ( "User-Agent" , userAgent ) ;
132
+ client . Timeout = TimeSpan . FromMilliseconds ( web . Timeout ) ;
133
+ client . DefaultRequestHeaders . Add ( "User-Agent" , web . UserAgent ) ;
133
134
return client ;
134
135
} ) ;
135
136
}
@@ -2422,16 +2423,16 @@ public async Task<HtmlDocument> LoadFromWebAsync(Uri uri, Encoding encoding, Net
2422
2423
if ( credentials != null || CaptureRedirect )
2423
2424
{
2424
2425
client = new HttpClient ( clientHandler ) ;
2425
-
2426
+ client . Timeout = TimeSpan . FromMilliseconds ( Timeout ) ;
2426
2427
//https://stackoverflow.com/questions/44076962/how-do-i-set-a-default-user-agent-on-an-httpclient
2427
2428
client . DefaultRequestHeaders . Add ( "User-Agent" , this . UserAgent ) ;
2428
2429
}
2429
2430
else
2430
2431
{
2431
- client = GetSharedHttpClient ( this . UserAgent ) ;
2432
+ client = GetSharedHttpClient ( this ) ;
2432
2433
}
2433
2434
2434
- client . Timeout = TimeSpan . FromMilliseconds ( Timeout ) ;
2435
+
2435
2436
2436
2437
var e = await client . GetAsync ( uri , cancellationToken ) . ConfigureAwait ( false ) ;
2437
2438
_statusCode = e . StatusCode ;
0 commit comments