Bug #13351
Updated by shyouhei (Shyouhei Urabe) over 7 years ago
Hello, `start` start is defined as: ~~~ruby 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 args is empty, all args passed to `new()` new() are `nil`. nil. However, not all `new()` new() args uses `nil` nil as default value: ~~~ruby def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil) ~~~ `p_addr` p_addr should be `:ENV` :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