Feature #12062
closedsupporting CIDR in ENV["no_proxy"]
Description
Ruby supports ENV["no_proxy"]
in lib/uri/generic.rb
Current implementation expects comma separated hostname suffix and exact IP address.
It is similar to wget
implementation.
(the difference is wget
does suffix match only no_proxy
hostname begins with period. But this difference is not so harmful.)
Current Implementation¶
Ruby doesn't support CIDR style(ex. 192.168.2.0/24
) no_proxy
instruction.
It is also mentioned too in this post.
http://unix.stackexchange.com/questions/23452/set-a-network-range-in-the-no-proxy-environment-variable
Workaround¶
And mentioned workaround is below.
printf -v no_proxy '%s,' 10.1.{1..255}.{1..255};
export no_proxy="${no_proxy%,}";
I think it is ugly solution.
If one doesn't want to use proxy in private network(it is very common in company's network)
It may require configuration like
no_proxy=10.0.0.0,10.0.0.1,10.0.0.......10.255.255.255(about 219MB)
length of ENV["no_proxy"]
will become about 219MB(!!)
It will take much more time in Ruby's URI implementation right now.
current lib/uri/generic.rb
is below.
no_proxy.scan(/([^:,]*)(?::(\d+))?/) {|host, port|
if /(\A|\.)#{Regexp.quote host}\z/i =~ self.host &&
(!port || self.port == port.to_i)
return nil
end
}
It requires regexp engine searching over 219MB string's data.
Long config file cause terrible performance suffer.
Linux standard might be wget
, but Python does not.
Python implementation in a widely used library requests is here
Suggetsion¶
I think Python's solution is cool and fast and minimize surprising.
So I wish ruby to support CIDR style no_proxy
instruction like Python.