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 /test | |
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 'test')
-rw-r--r-- | test/net/http/test_http.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index cfdf62191f..052c3ef558 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -896,6 +896,23 @@ class TestNetHTTPKeepAlive < Test::Unit::TestCase } end + def test_server_closed_connection_auto_reconnect + start {|http| + res = http.get('/') + http.keep_alive_timeout = 5 + assert_kind_of Net::HTTPResponse, res + assert_kind_of String, res.body + sleep 1.5 + assert_nothing_raised { + # Net::HTTP should detect the closed connection before attempting the + # request, since post requests cannot be retried. + res = http.post('/', 'query=foo', 'content-type' => 'application/x-www-form-urlencoded') + } + assert_kind_of Net::HTTPResponse, res + assert_kind_of String, res.body + } + end + def test_keep_alive_get_auto_retry start {|http| res = http.get('/') |