Bug #6001 » net.http.retry_errors.2.patch
| lib/net/http.rb (working copy) | ||
|---|---|---|
|
#
|
||
|
class HTTP < Protocol
|
||
|
class OpenTimeout < Timeout::Error
|
||
|
end
|
||
|
# :stopdoc:
|
||
|
Revision = %q$Revision$.split[1]
|
||
|
HTTPVersion = '1.1'
|
||
| ... | ... | |
|
def connect
|
||
|
D "opening connection to #{conn_address()}..."
|
||
|
s = timeout(@open_timeout) { TCPSocket.open(conn_address(), conn_port()) }
|
||
|
s = timeout(@open_timeout, OpenTimeout) {
|
||
|
TCPSocket.open(conn_address(), conn_port())
|
||
|
}
|
||
|
D "opened"
|
||
|
if use_ssl?
|
||
|
ssl_parameters = Hash.new
|
||
| ... | ... | |
|
end
|
||
|
# Server Name Indication (SNI) RFC 3546
|
||
|
s.hostname = @address if s.respond_to? :hostname=
|
||
|
timeout(@open_timeout) { s.connect }
|
||
|
timeout(@open_timeout, OpenTimeout) { s.connect }
|
||
|
if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
|
||
|
s.post_connection_check(@address)
|
||
|
end
|
||
| ... | ... | |
|
}
|
||
|
res
|
||
|
}
|
||
|
end_transport req, res
|
||
|
res
|
||
|
rescue EOFError, Errno::ECONNRESET => exception
|
||
|
rescue IOError, EOFError,
|
||
|
Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE,
|
||
|
OpenSSL::SSL::SSLError, Timeout::Error => exception
|
||
|
raise if OpenTimeout === exception
|
||
|
if count == 0 && IDEMPOTENT_METHODS_.include?(req.method)
|
||
|
count += 1
|
||
|
@socket.close if @socket and not @socket.closed?
|
||
| ... | ... | |
|
D "Conn close because of error #{exception}"
|
||
|
@socket.close if @socket and not @socket.closed?
|
||
|
raise
|
||
|
rescue => exception
|
||
|
D "Conn close because of error #{exception}"
|
||
|
@socket.close if @socket and not @socket.closed?
|
||
|
raise exception
|
||
|
end
|
||
|
end_transport req, res
|
||
|
res
|
||
|
rescue => exception
|
||
|
D "Conn close because of error #{exception}"
|
||
|
@socket.close if @socket and not @socket.closed?
|
||
|
raise exception
|
||
|
end
|
||
|
def begin_transport(req)
|
||
| test/net/http/test_http.rb (working copy) | ||
|---|---|---|
|
def test_timeout_during_HTTP_session
|
||
|
bug4246 = "expected the HTTP session to have timed out but have not. c.f. [ruby-core:34203]"
|
||
|
# listen for connections... but deliberately do not complete SSL handshake
|
||
|
# listen for connections... but deliberately do not read
|
||
|
TCPServer.open('localhost', 0) {|server|
|
||
|
port = server.addr[1]
|
||
|
conn = Net::HTTP.new('localhost', port)
|
||
|
conn.read_timeout = 1
|
||
|
conn.open_timeout = 1
|
||
|
conn.read_timeout = 0.01
|
||
|
conn.open_timeout = 0.01
|
||
|
th = Thread.new do
|
||
|
assert_raise(Timeout::Error) {
|
||
| ... | ... | |
|
assert_kind_of Net::HTTPResponse, res
|
||
|
assert_kind_of String, res.body
|
||
|
sleep 1.5
|
||
|
assert_nothing_raised {
|
||
|
res = http.get('/')
|
||
|
}
|
||
|
res = http.get('/')
|
||
|
assert_kind_of Net::HTTPResponse, res
|
||
|
assert_kind_of String, res.body
|
||
|
}
|
||
|
end
|
||
|
def test_keep_alive_EOF
|
||
|
def test_keep_alive_server_close
|
||
|
def @server.run(sock)
|
||
|
sock.close
|
||
|
end
|
||
|
start {|http|
|
||
|
assert_raises(EOFError) {
|
||
|
assert_raises(IOError) {
|
||
|
res = http.get('/')
|
||
|
}
|
||
|
}
|
||
- « Previous
- 1
- 2
- Next »