Sometimes Apache will send a connection header like this:

  Connection: Keep-Alive, close

then close the connection.  Net::HTTP#keep_alive? does not handle this
response correctly.  It returns true when it should return false.
Testing for closed state before keep-alive seems to do the trick.

Here is my patch (against 1.8.6):

Index: lib/net/http.rb
===================================================================
--- lib/net/http.rb     (revision 12131)
+++ lib/net/http.rb     (working copy)
@@ -1089,10 +1089,10 @@
     def keep_alive?(req, res)
       return false if /close/i =~ req['connection'].to_s
       return false if @seems_1_0_server
+      return false if /close/i      =~ res['connection'].to_s
       return true  if /keep-alive/i =~ res['connection'].to_s
-      return false if /close/i      =~ res['connection'].to_s
+      return false if /close/i      =~ res['proxy-connection'].to_s
       return true  if /keep-alive/i =~ res['proxy-connection'].to_s
-      return false if /close/i      =~ res['proxy-connection'].to_s
       (@curr_http_version == '1.1')
     end


-- 
Aaron Patterson
http://tenderlovemaking.com/