Project

General

Profile

Actions

Bug #4522

closed

Net::HTTP persistent connections

Added by mksm (Ricardo Amorim) over 13 years ago. Updated over 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-linux]
Backport:
[ruby-core:<unknown>]

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.

Actions

Also available in: Atom PDF

Like0
Like0Like0