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 #1

Updated by shyouhei (Shyouhei Urabe) over 7 years ago

  • Description updated (diff)
Actions #2

Updated by naruse (Yui NARUSE) over 7 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.

Actions #3

Updated by usa (Usaku NAKAMURA) over 7 years ago

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

Updated by usa (Usaku NAKAMURA) over 7 years ago

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

Updated by naruse (Yui NARUSE) about 7 years ago

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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0