Skip to content

Commit 913690f

Browse files
committed
Short-circuit DNS lookup if hostname matches no_proxy
1 parent e3027ef commit 913690f

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

lib/uri/generic.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,18 +1552,21 @@ def find_proxy(env=ENV)
15521552
return nil
15531553
end
15541554

1555-
if self.hostname
1555+
name = 'no_proxy'
1556+
if self.hostname && (no_proxy = env[name] || env[name.upcase])
1557+
if no_proxy && !URI::Generic.use_proxy?(self.hostname, nil, self.port, no_proxy)
1558+
return nil
1559+
end
1560+
15561561
begin
15571562
addr = IPSocket.getaddress(self.hostname)
15581563
return nil if /\A127\.|\A::1\z/ =~ addr
15591564
rescue SocketError
15601565
end
1561-
end
15621566

1563-
name = 'no_proxy'
1564-
if no_proxy = env[name] || env[name.upcase]
1565-
return nil unless URI::Generic.use_proxy?(self.hostname, addr, self.port, no_proxy)
1567+
return nil if no_proxy && !URI::Generic.use_proxy?(self.hostname, addr, self.port, no_proxy)
15661568
end
1569+
15671570
URI.parse(proxy_uri)
15681571
end
15691572

0 commit comments

Comments
 (0)