Since IPv6 addresses are wrapped by brackets in URIs, this method returns
IPv6 addresses wrapped by brackets. This form is not appropriate to pass
socket methods such as TCPSocket.open. If unwrapped host names are
required, use “hostname” method.

#scheme ⇒ Object

Class Method Details

.build(args) ⇒ Object

Synopsis

See #new

Description

Creates a new URI::Generic instance from components of URI::Generic with
check. Components are: scheme, userinfo, host, port, registry, path,
opaque, query and fragment. You can provide arguments either by an Array or
a Hash. See #new for hash keys to use or for order of array items.

# File 'lib/uri/generic.rb', line 116defself.build(args)ifargs.kind_of?(Array)&&args.size==::URI::Generic::COMPONENT.sizetmp=args.dupelsifargs.kind_of?(Hash)tmp=::URI::Generic::COMPONENT.collectdo|c|ifargs.include?(c)args[c]elsenilendendelsecomponent=self.class.componentrescue::URI::Generic::COMPONENTraiseArgumentError,"expected Array of or Hash of components of #{self.class} (#{component.join(', ')})"endtmp<<niltmp<<truereturnself.new(*tmp)end

.build2(args) ⇒ Object

Synopsis

See #new

Description

At first, tries to create a new URI::Generic instance using
URI::Generic::build. But, if exception URI::InvalidComponentError is
raised, then it URI::Escape.escape all URI components and tries again.

But http_proxy and HTTP_PROXY is treated specially under CGI environment.
It's because HTTP_PROXY may be set by Proxy: header. So HTTP_PROXY is
not used. http_proxy is not used too if the variable is case insensitive.
CGI_HTTP_PROXY can be used instead.

# File 'lib/uri/generic.rb', line 1497deffind_proxyraiseBadURIError,"relative URI: #{self}"ifself.relative?name=self.scheme.downcase+'_proxy'proxy_uri=nilifname=='http_proxy'&&ENV.include?('REQUEST_METHOD')# CGI?
# HTTP_PROXY conflicts with *_proxy for proxy settings and
# HTTP_* for header information in CGI.
# So it should be careful to use it.
pairs=ENV.reject{|k,v|/\Ahttp_proxy\z/i!~k}casepairs.lengthwhen0# no proxy setting anyway.
proxy_uri=nilwhen1k,_=pairs.shiftifk=='http_proxy'&&ENV[k.upcase]==nil# http_proxy is safe to use because ENV is case sensitive.
proxy_uri=ENV[name]elseproxy_uri=nilendelse# http_proxy is safe to use because ENV is case sensitive.
proxy_uri=ENV.to_hash[name]endif!proxy_uri# Use CGI_HTTP_PROXY. cf. libwww-perl.
proxy_uri=ENV["CGI_#{name.upcase}"]endelsifname=='http_proxy'unlessproxy_uri=ENV[name]ifproxy_uri=ENV[name.upcase]warn'The environment variable HTTP_PROXY is discouraged. Use http_proxy.'endendelseproxy_uri=ENV[name]||ENV[name.upcase]endifproxy_uri.nil?||proxy_uri.empty?returnnilendifself.hostnamerequire'socket'beginaddr=IPSocket.getaddress(self.hostname)returnnilif/\A127\.|\A::1\z/=~addrrescueSocketErrorendendname='no_proxy'ifno_proxy=ENV[name]||ENV[name.upcase]no_proxy.scan(/([^:,]*)(?::(\d+))?/){|host,port|if/(\A|\.)#{Regexp.quotehost}\z/i=~self.host&&(!port||self.port==port.to_i)returnnilend}endURI.parse(proxy_uri)end

# File 'lib/uri/generic.rb', line 1272defroute_from(oth)# you can modify `rel', but can not `oth'.
beginoth,rel=route_from0(oth)rescueraise$!.class,$!.messageendifoth==relreturnrelendrel.set_path(route_from_path(oth.path,self.path))ifrel.path=='./'&&self.query# "./?foo" -> "?foo"
rel.set_path('')endreturnrelend