fix ipaddr parameter of Net::HTTP.start to support proxy

54072e329c
This commit is contained in:
NARUSE, Yui 2019-12-10 19:06:13 +09:00
Родитель aedbee52c0
Коммит af11efd377
2 изменённых файлов: 40 добавлений и 1 удалений

Просмотреть файл

@ -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')

Просмотреть файл

@ -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"))