In order to reuse open TCP connections with HttpClient
you have to share a single instance for all requests.
This means that we cannot simply instantiate HttpClient
with different settings (e.g. timeout or headers).
How can we share the connections and use different settings at the same time? This was very easy, in fact the default, with the older HttpWebRequest
and WebClient
infrastructure.
Note, that simply setting HttpClient.Timeout
before making a request is not thread safe and would not work in a concurrent application (e.g. an ASP.NET web site).
Timeout
? Things like headers are settable per request, and varyingBaseAddress
doesn't make much sense because each different one will require a new connection anyway. Practically speaking,Timeout
might be the only property you'd want to vary on the same instance. I can show you how to use a different timeout per request if that answers the question.HttpClient
means you are reusing a single TCP connection. There is no "pooling" involved here.