def self.net_connect_explicit_allowed?(allowed, uri=nil)
case allowed
when Array
allowed.any? { |allowed_item| net_connect_explicit_allowed?(allowed_item, uri) }
when Regexp
uri.to_s =~ allowed ||
uri.omit(:port).to_s =~ allowed && uri.port == uri.default_port
when String
allowed == uri.to_s ||
allowed == uri.host ||
allowed == "#{uri.host}:#{uri.port}" ||
allowed == "#{uri.scheme}://#{uri.host}:#{uri.port}" ||
allowed == "#{uri.scheme}://#{uri.host}" && uri.port == uri.default_port
else
if allowed.respond_to?(:call)
allowed.call(uri)
end
end
end