Question

I'm using httpclient to download multiple small files from server continuously. So I want to reuse the httpclient connection to avoid costing a lot of time to allocate new connection.

And I already have some client code to try to reuse the connection, and set the idle timeout of existing connection to 3 minutes.

However the response from server always contains "Connection: close[\r][\n]", httpclient library releases the connection immediately after it meets such header.

How do I do to let httpclient to ignore the response from server, or which header I post could let server no longer return such closing header?

Was it helpful?

Solution

Even if you manage to ignore the Connection: close header, I don't think it would be a good idea "violate" the directive.

The RFC says the following

HTTP/1.1 defines the "close" connection option for the sender to signal that the connection will be closed after completion of the response. For example,

   Connection: close

in either the request or the response header fields indicates that the connection SHOULD NOT be considered `persistent' (section 8.1) after the current request/response is complete.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top