From af11efd377965b6601bb54aa79072ef0789dc525 Mon Sep 17 00:00:00 2001 From: "NARUSE, Yui" Date: Tue, 10 Dec 2019 19:06:13 +0900 Subject: [PATCH] fix ipaddr parameter of Net::HTTP.start to support proxy 54072e329cab7207fba133caba4fc12b45add8f9 --- lib/net/http.rb | 2 +- test/net/http/test_https.rb | 39 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/net/http.rb b/lib/net/http.rb index a62f59af8f..88a174a248 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -971,7 +971,7 @@ module Net #:nodoc: write_timeout: @write_timeout, continue_timeout: @continue_timeout, debug_output: @debug_output) - buf = "CONNECT #{@address}:#{@port} HTTP/#{HTTPVersion}\r\n" + buf = "CONNECT #{conn_address}:#{@port} HTTP/#{HTTPVersion}\r\n" buf << "Host: #{@address}:#{@port}\r\n" if proxy_user credential = ["#{proxy_user}:#{proxy_pass}"].pack('m0') diff --git a/test/net/http/test_https.rb b/test/net/http/test_https.rb index 3e918a1ced..17fabb62d5 100644 --- a/test/net/http/test_https.rb +++ b/test/net/http/test_https.rb @@ -67,6 +67,45 @@ class TestNetHTTPS < Test::Unit::TestCase assert_equal(SERVER_CERT.to_der, certs[1].to_der) end + def test_get_SNI_proxy + TCPServer.open("127.0.0.1", 0) {|serv| + _, port, _, _ = serv.addr + client_thread = Thread.new { + proxy = Net::HTTP.Proxy("127.0.0.1", port, 'user', 'password') + http = proxy.new("foo.example.org", 8000) + http.ipaddr = "192.0.2.1" + http.use_ssl = true + http.cert_store = TEST_STORE + certs = [] + http.verify_callback = Proc.new do |preverify_ok, store_ctx| + certs << store_ctx.current_cert + preverify_ok + end + begin + http.start + rescue EOFError + end + } + server_thread = Thread.new { + sock = serv.accept + begin + proxy_request = sock.gets("\r\n\r\n") + assert_equal( + "CONNECT 192.0.2.1:8000 HTTP/1.1\r\n" + + "Host: foo.example.org:8000\r\n" + + "Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==\r\n" + + "\r\n", + proxy_request, + "[ruby-dev:25673]") + ensure + sock.close + end + } + assert_join_threads([client_thread, server_thread]) + } + + end + def test_get_SNI_failure TestNetHTTPUtils.clean_http_proxy_env do http = Net::HTTP.new("invalid_servername", config("port"))