HttpClient
is a facade to the request execution pipeline. The exact composition of the execution pipeline depends on the configuration of the HttpClient
instance. Think of it as a browser with multiple tabs.
One of more HttpClient
instances can depend on one ClientConnectionManager
sharing the underlying pool of persistent connections. ClientConnectionManager
instances have no knowledge of HttpClient
instances that depend upon them. They just lease connections to whatever entity requests them.
Each request is executed within a particular HttpContext
. HttpContext
instance is a collection of all stateful objects involved in execution of the actual HTTP exchange. HttpContext
instances are not thread-safe and may not be shared by multiple worker threads.
When initiating an HTTP exchange HttpClient
leases a ManagedClientConnection
instance from the ClientConnectionManager
it is associated with. It serializes and transmits the request message to the opposite endpoint, receives a response head, and binds the underlying connection to the response HttpEntity
instance (when available) without reading the response content. This enables the consumer of HttpResponse instance stream the response content without intermediate in-memory buffering. This also makes it necessary for the consumer to ensure proper release of resources (in particular ManagedClientConnection
) associated with the response.