Bug #4522
closedNet::HTTP persistent connections
Description
Net::HTTP does not seem to follow HTTP 1.1 recommendations regarding persistent connections as per: http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html.
http://pastie.org/1710531 is a test script to reproduce the issue and inspect the TCPSocket:
Example 01 works according to RFC but it's required to manually initiate the connection before using any method (GET).
Example 02 shows that Net::HTTP sends a "Connection: close" header if the connection was not already open. This is not good :(
Example 03 shows that Net::HTTP properly sends a "Connection: keep-alive" header but closes the socket anyways. :(
I can post a patch if this issue is accepted.
Updated by romanbsd (Roman Shterenzon) over 13 years ago
And if it's used like in example #1, and then there's an exception (which is rescued in user code), and then a new request is issued - would it still use Keep-Alive? Because if it will, then at least the bug can be worked-around...
Updated by naruse (Yui NARUSE) over 13 years ago
- Status changed from Open to Rejected
Recommended use of Net::HTTP is like:
Net::HTTP.start("www.terra.com.br") do |h|
h.get("/")
end
So if a code is against this, it has some intention like the connection is one time connection.
On this recognition, current behavior seems reasonable.