Project

General

Profile

Bug #11526 » no_retry_http_streams.diff

Patch that changes Net::HTTP behavior to only retry the request if a block is not given - tdg5 (Danny Guinther), 09/14/2015 07:12 PM

View differences:

lib/net/http.rb
# avoid a dependency on OpenSSL
defined?(OpenSSL::SSL) ? OpenSSL::SSL::SSLError : IOError,
Timeout::Error => exception
if count == 0 && IDEMPOTENT_METHODS_.include?(req.method)
if count == 0 && IDEMPOTENT_METHODS_.include?(req.method) && !block_given?
count += 1
@socket.close if @socket and not @socket.closed?
D "Conn close because of error #{exception}, and retry"
test/net/http/test_http.rb
include TestNetHTTPUtils
def test_keep_alive_get_auto_reconnect
start {|http|
http = new
res = http.get('/')
http.keep_alive_timeout = 1
assert_kind_of Net::HTTPResponse, res
assert_kind_of String, res.body
sleep 1.5
assert_nothing_raised {
res = http.get('/')
http.keep_alive_timeout = 1
assert_kind_of Net::HTTPResponse, res
assert_kind_of String, res.body
sleep 1.5
assert_nothing_raised {
res = http.get('/')
}
assert_kind_of Net::HTTPResponse, res
assert_kind_of String, res.body
}
assert_kind_of Net::HTTPResponse, res
assert_kind_of String, res.body
end
def test_keep_alive_get_auto_retry
start {|http|
http = new
res = http.get('/')
http.keep_alive_timeout = 5
assert_kind_of Net::HTTPResponse, res
assert_kind_of String, res.body
sleep 1.5
res = http.get('/')
assert_kind_of Net::HTTPResponse, res
assert_kind_of String, res.body
end
def test_keep_alive_no_auto_retry_block
start do |http|
res = http.get('/')
http.keep_alive_timeout = 5
assert_kind_of Net::HTTPResponse, res
assert_kind_of String, res.body
sleep 1.5
res = http.get('/')
assert_raises(EOFError) { res = http.get('/') }
assert_kind_of Net::HTTPResponse, res
assert_kind_of String, res.body
}
end
end
def test_keep_alive_server_close
(1-1/3)