diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-27 14:07:35 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-27 14:07:35 +0000 |
commit | 7809218a5abd5efdc74ee72b3e24c11297add1e4 (patch) | |
tree | 036582b4735840126daafde1a719e246dc38b075 /lib/net/http.rb | |
parent | 68d96dc5d75fc8f1a9c6344800c91789a67a50de (diff) | |
download | ruby-7809218a5abd5efdc74ee72b3e24c11297add1e4.tar.gz |
* lib/net/http.rb (connect): detect closed connection and reconnect
If the server closes a keep-alive http connection, the client socket
reaches EOF. To avoid an EOFError, detect the closed connection and
reconnect.
Added test to ensure HTTP#post succeeds even if the
keep-alive-connection has been closed by the server.
by Kristian Hanekamp <kris.hanekamp@gmail.com>
https://github.com/ruby/ruby/pull/1089 fix GH-1089
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net/http.rb')
-rw-r--r-- | lib/net/http.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb index 5ccf653d37..65cacbd175 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -1473,10 +1473,16 @@ module Net #:nodoc: def begin_transport(req) if @socket.closed? connect - elsif @last_communicated && @last_communicated + @keep_alive_timeout < Process.clock_gettime(Process::CLOCK_MONOTONIC) - D 'Conn close because of keep_alive_timeout' - @socket.close - connect + elsif @last_communicated + if @last_communicated + @keep_alive_timeout < Process.clock_gettime(Process::CLOCK_MONOTONIC) + D 'Conn close because of keep_alive_timeout' + @socket.close + connect + elsif @socket.io.wait_readable(0) && @socket.eof? + D "Conn close because of EOF" + @socket.close + connect + end end if not req.response_body_permitted? and @close_on_empty_response |