Skip to content

Commit 7f0358a

Browse files
committed
non handler disposal on client disposal
1 parent 2c912bb commit 7f0358a

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/HttpClientCache.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ private HttpClient CreateHttpClient(HttpClientOptions? options)
5252
{
5353
if (RuntimeUtil.IsBrowser())
5454
{
55-
return options?.HttpClientHandler != null ? new HttpClient(options.HttpClientHandler) : new HttpClient();
55+
return options?.HttpClientHandler != null ? new HttpClient(options.HttpClientHandler, disposeHandler: false) : new HttpClient();
5656
}
5757

58-
return options?.HttpClientHandler != null ? new HttpClient(options.HttpClientHandler) : new HttpClient(GetOrCreateHandler(options));
58+
return options?.HttpClientHandler != null
59+
? new HttpClient(options.HttpClientHandler, disposeHandler: false)
60+
: new HttpClient(GetOrCreateHandler(options), disposeHandler: false);
5961
}
6062

6163
public ValueTask<HttpClient> Get(string id, HttpClientOptions? options = null, CancellationToken cancellationToken = default)
@@ -113,11 +115,8 @@ private static async ValueTask ConfigureHttpClient(HttpClient httpClient, HttpCl
113115

114116
private SocketsHttpHandler GetOrCreateHandler(HttpClientOptions? options)
115117
{
116-
var key = new HandlerKey(
117-
options?.PooledConnectionLifetime?.TotalSeconds ?? 600,
118-
options?.MaxConnectionsPerServer ?? 40,
119-
options?.UseCookieContainer == true
120-
);
118+
var key = new HandlerKey(options?.PooledConnectionLifetime?.TotalSeconds ?? 600, options?.MaxConnectionsPerServer ?? 40,
119+
options?.UseCookieContainer == true);
121120

122121
return _handlers.GetOrAdd(key, _ =>
123122
{

0 commit comments

Comments
 (0)