Project

General

Profile

Bug #13351

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

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

Status:
Closed
Priority:
Normal
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

Related to Ruby master - Feature #8771: Start does not use proxy configuration form ENV variablesClosedActions

Associated revisions

Revision 67723c1e
Added by naruse (Yui NARUSE) over 2 years ago

Net::HTTP#start now pass :ENV to p_addr by default [Bug #13351]

To avoid this, pass nil explicitly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 58798
Added by naruse (Yui NARUSE) over 2 years ago

Net::HTTP#start now pass :ENV to p_addr by default [Bug #13351]

To avoid this, pass nil explicitly.

Revision 58798
Added by naruse (Yui NARUSE) over 2 years ago

Net::HTTP#start now pass :ENV to p_addr by default [Bug #13351]

To avoid this, pass nil explicitly.

Revision 58798
Added by naruse (Yui NARUSE) over 2 years ago

Net::HTTP#start now pass :ENV to p_addr by default [Bug #13351]

To avoid this, pass nil explicitly.

History

#1

Updated by shyouhei (Shyouhei Urabe) over 2 years ago

  • Description updated (diff)
#2

Updated by naruse (Yui NARUSE) over 2 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r58798.


Net::HTTP#start now pass :ENV to p_addr by default [Bug #13351]

To avoid this, pass nil explicitly.

#3

Updated by usa (Usaku NAKAMURA) over 2 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: WONTFIX, 2.3: REQUIRED, 2.4: REQUIRED
#4

Updated by usa (Usaku NAKAMURA) over 2 years ago

  • Backport changed from 2.2: WONTFIX, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: WONTFIX, 2.3: WONTFIX, 2.4: UNKNOWN
#5

Updated by naruse (Yui NARUSE) about 2 years ago

  • Related to Feature #8771: Start does not use proxy configuration form ENV variables added

Also available in: Atom PDF