diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-05-17 07:40:01 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-05-17 07:40:01 +0000 |
commit | d50ecb63ec02043865a4217af7e738f22ea6e8c7 (patch) | |
tree | 392ef62399657b972e91dd4f8d50494454b8a29f /lib | |
parent | 5a1dfb04bc2b09fcf8f3427cac72d0ce52a45eb2 (diff) |
http_proxy setting should respect both parent domain and subdomain
URI::Generic: Respect no_proxy for both parent domain and
subdomains It is now possible to add just the subdomains for proxy bypass. In
a setting where the main domain needs to go through proxy while the
subdomains don't, it is now possible to just add the subdomains to the
no_proxy list.
The assumption that subdomains and the parent domain should
behave the same wrt no_proxy has been removed.
eg: Adding .example.com in no_proxy would allow example.com
to go through the proxy.
From: Harsimran Singh Maan <maan.harry@gmail.com>
fix https://github.com/ruby/ruby/pull/1748
[Bug #14345]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/uri/generic.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index 799ad13471..0948cba66d 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -1543,11 +1543,16 @@ module URI end def self.use_proxy?(hostname, addr, port, no_proxy) # :nodoc: - no_proxy.scan(/(?!\.)([^:,\s]+)(?::(\d+))?/) {|p_host, p_port| + hostname = hostname.downcase + dothostname = ".#{hostname}" + no_proxy.scan(/([^:,\s]+)(?::(\d+))?/) {|p_host, p_port| if !p_port || port == p_port.to_i - if /(\A|\.)#{Regexp.quote p_host}\z/i =~ hostname - return false - elsif addr + if p_host.start_with?('.') + return false if hostname.end_with?(p_host.downcase) + else + return false if dothostname.end_with?(".#{p_host.downcase}") + end + if addr begin return false if IPAddr.new(p_host).include?(addr) rescue IPAddr::InvalidAddressError |