Does HttpClient use the same ServicePoint Connection Limit as HttpWebRequest?
Thanks
The answer is not complete. It depends on implementation. In .net core ServicePointManager.DefaultConnectionLimit setting is not used, HttpClientHandler.MaxConnectionsPerServer should be used instead.
services.AddHttpClient(clientName).ConfigurePrimaryHttpMessageHandler(sp => new HttpClientHandler() { MaxConnectionsPerServer = 2 });
Also note that SocketsHttpHandler
is the newer implementation of HttpMessageHandler
compared to HttpClientHandler
, but you can still use HttpClientHandler
as it seems to be more flexible and just forwards through to SocketsHttpHandler
anyway.
Since I couldn't find an official answer anywhere in the docs, decompiling the code for .NET 6 yields a default value of int.MaxValue
for HttpClientHandler.MaxConnectionsPerServer
.
This should also be true for any version of .NET Core.
namespace System.Net.Http
{
internal static partial class HttpHandlerDefaults
{
public const int DefaultMaxConnectionsPerServer = int.MaxValue;
...
}
}
It uses the same ServicePointManager so the answer is yes.
You can change the limit programmatically though if you want, see this