mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
CIDR in no_proxy
* lib/uri/generic.rb (URI::Generic#find_proxy): support CIDR in no_proxy. [ruby-core:73769] [Feature#12062] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53817 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
423d042371
commit
1ee9cad027
3 changed files with 25 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
|||
Sat Feb 13 17:30:49 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* lib/uri/generic.rb (URI::Generic#find_proxy): support CIDR in
|
||||
no_proxy. [ruby-core:73769] [Feature#12062]
|
||||
|
||||
Sat Feb 13 17:11:58 2016 Fabian Wiesel <fabian.wiesel@sap.com>
|
||||
|
||||
* lib/uri/generic.rb (find_proxy): exclude white-spaces and allow
|
||||
|
|
|
@ -1547,9 +1547,18 @@ module URI
|
|||
name = 'no_proxy'
|
||||
if no_proxy = ENV[name] || ENV[name.upcase]
|
||||
no_proxy.scan(/(?!\.)([^:,\s]+)(?::(\d+))?/) {|host, port|
|
||||
if /(\A|\.)#{Regexp.quote host}\z/i =~ self.host &&
|
||||
(!port || self.port == port.to_i)
|
||||
return nil
|
||||
if (!port || self.port == port.to_i)
|
||||
if /(\A|\.)#{Regexp.quote host}\z/i =~ self.host
|
||||
return nil
|
||||
else
|
||||
require 'ipaddr'
|
||||
return nil if
|
||||
begin
|
||||
IPAddr.new(host)
|
||||
rescue IPAddr::InvalidAddressError
|
||||
next
|
||||
end.include?(self.host)
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
|
|
|
@ -841,6 +841,14 @@ class URI::TestGeneric < Test::Unit::TestCase
|
|||
}
|
||||
end
|
||||
|
||||
def test_find_proxy_no_proxy_cidr
|
||||
with_env('http_proxy'=>'http://127.0.0.1:8080', 'no_proxy'=>'192.0.2.0/24') {
|
||||
assert_equal(URI('http://127.0.0.1:8080'), URI("http://192.0.1.1/").find_proxy)
|
||||
assert_nil(URI("http://192.0.2.1/").find_proxy)
|
||||
assert_nil(URI("http://192.0.2.2/").find_proxy)
|
||||
}
|
||||
end
|
||||
|
||||
def test_find_proxy_bad_value
|
||||
with_env('http_proxy'=>'') {
|
||||
assert_nil(URI("http://192.0.2.1/").find_proxy)
|
||||
|
|
Loading…
Reference in a new issue