Project

General

Profile

Actions

Bug #13351

closed

net/http: Net::HTTP.start sets wrong default arg value

Added by luizluca (Luiz Angelo Daros de Luca) over 7 years ago. Updated over 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.0p0 (2016-12-24 revision 57164) [mips-linux-gnu]
[ruby-core:80272]

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 args 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


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #8771: Start does not use proxy configuration form ENV variablesClosednaruse (Yui NARUSE)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0