Actions
Bug #13351
closednet/http: Net::HTTP.start sets wrong default arg value
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.0p0 (2016-12-24 revision 57164) [mips-linux-gnu]
Description
Hello,
start
is defined as:
def HTTP.start(address, *arg, &block) # :yield: +http+
arg.pop if opt = Hash.try_convert(arg[-1])
port, p_addr, p_port, p_user, p_pass = *arg
port = https_default_port if !port && opt && opt[:use_ssl]
http = new(address, port, p_addr, p_port, p_user, p_pass)
So, if arg
s is empty, all args passed to new()
are nil
.
However, not all new()
args uses nil
as default value:
def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil)
p_addr
should be :ENV
if not provided. The result is that:
ruby -r net/http -e 'p Net::HTTP.new("www.google.com","80").start {|http| p http.get("/") }'
#<Net::HTTPFound 302 Found readbody=true>
Correctly uses the proxy env vars while this fails:
ruby -r net/http -e 'p Net::HTTP.start("www.google.com","80") {|http| p http.get("/") }'
/usr/lib64/ruby/2.2.0/net/http.rb:879:in `initialize': Network is unreachable - connect(2) for "www.google.com" port 80 (Errno::ENETUNREACH)
And docs says it should work.
This already happens on ruby 2.2.6p396
Actions
Like0
Like0Like0Like0Like0Like0