From 62941003a2f5314e80daf0c16e51881f0d177ff5 Mon Sep 17 00:00:00 2001 From: yugui Date: Sun, 16 Jan 2011 12:35:11 +0000 Subject: merges r30520 from trunk into ruby_1_9_2. -- * lib/net/http.rb (Net::HTTP#connect): makes it timeout during SSL handshake too. [ruby-core:34203] Patch by Marc Slemko. * test/net/http/test_http.rb (TestNetHTTP_v1_2#test_timeout_during_HTTP_session): test for [ruby-core:34203] * test/net/http/test_https.rb (TestNetHTTPS#test_timeout_during_SSL_handshake): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@30571 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/net/http.rb | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/net/http.rb b/lib/net/http.rb index 8abbf60e58..ea5e449fcd 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -662,21 +662,27 @@ module Net #:nodoc: @socket.read_timeout = @read_timeout @socket.debug_output = @debug_output if use_ssl? - if proxy? - @socket.writeline sprintf('CONNECT %s:%s HTTP/%s', - @address, @port, HTTPVersion) - @socket.writeline "Host: #{@address}:#{@port}" - if proxy_user - credential = ["#{proxy_user}:#{proxy_pass}"].pack('m') - credential.delete!("\r\n") - @socket.writeline "Proxy-Authorization: Basic #{credential}" + begin + if proxy? + @socket.writeline sprintf('CONNECT %s:%s HTTP/%s', + @address, @port, HTTPVersion) + @socket.writeline "Host: #{@address}:#{@port}" + if proxy_user + credential = ["#{proxy_user}:#{proxy_pass}"].pack('m') + credential.delete!("\r\n") + @socket.writeline "Proxy-Authorization: Basic #{credential}" + end + @socket.writeline '' + HTTPResponse.read_new(@socket).value end - @socket.writeline '' - HTTPResponse.read_new(@socket).value - end - s.connect - if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE - s.post_connection_check(@address) + timeout(@open_timeout) { s.connect } + if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE + s.post_connection_check(@address) + end + rescue => exception + D "Conn close because of connect error #{exception}" + @socket.close if @socket and not @socket.closed? + raise exception end end on_connect -- cgit v1.2.3