Base class for all URI classes. Implements generic URI syntax as per RFC 2396.

Constants

An Array of the available components for URI::Generic.

A Default port of nil for URI::Generic.

No documentation available
Attributes

Returns the fragment component of the URI.

URI("http://foo/bar/baz?search=FooBar#ponies").fragment #=> "ponies"
Read

Returns the host component of the URI.

URI("http://foo/bar/baz").host #=> "foo"

It returns nil if no host component exists.

URI("mailto:foo@example.org").host #=> nil

The component does not contain the port number.

URI("http://foo:8080/bar/baz").host #=> "foo"

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

URI("http://[::1]/bar/baz").host     #=> "[::1]"
URI("http://[::1]/bar/baz").hostname #=> "::1"
Read

Returns the opaque part of the URI.

URI("mailto:foo@example.org").opaque #=> "foo@example.org"
URI("http://foo/bar/baz").opaque     #=> nil

The portion of the path that does not make use of the slash ‘/’. The path typically refers to an absolute path or an opaque part. (See RFC2396 Section 3 and 5.2.)

Read

Returns the path component of the URI.

URI("http://foo/bar/baz").path #=> "/bar/baz"
Read

Returns the port component of the URI.

URI("http://foo/bar/baz").port      #=> 80
URI("http://foo:8080/bar/baz").port #=> 8080
Read

Returns the query component of the URI.

URI("http://foo/bar/baz?search=FooBar").query #=> "search=FooBar"
Read

Returns the scheme component of the URI.

URI("http://foo/bar/baz").scheme #=> "http"
Class Methods

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.

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 does URI::Escape.escape all URI components and tries again.

Components of the URI in the order.

Returns default port.

Args

scheme

Protocol scheme, i.e. ‘http’,‘ftp’,‘mailto’ and so on.

userinfo

User name and password, i.e. ‘sdmitry:bla’.

host

Server host name.

port

Server port.

registry

Registry of naming authorities.

path

Path on server.

opaque

Opaque part.

query

Query data.

fragment

Part of the URI after ‘#’ character.

parser

Parser for internal use [URI::DEFAULT_PARSER by default].

arg_check

Check arguments [false by default].

Description

Creates a new URI::Generic instance from “generic” components without check.

Instance Methods
An alias for merge
An alias for route_from

Compares two URIs.

An alias for absolute?

Returns true if URI has a scheme (e.g. http:// or https://) specified.

Checks the host v component for RFC2396 compliance and against the URI::Parser Regexp for :HOST.

Can not have a registry or opaque component defined, with a host component defined.

Checks the opaque v component for RFC2396 compliance and against the URI::Parser Regexp for :OPAQUE.

Can not have a host, port, user, or path component defined, with an opaque component defined.

Checks the password v component for RFC2396 compliance and against the URI::Parser Regexp for :USERINFO.

Can not have a registry or opaque component defined, with a user component defined.

Checks the path v component for RFC2396 compliance and against the URI::Parser Regexp for :ABS_PATH and :REL_PATH.

Can not have a opaque component defined, with a path component defined.

Checks the port v component for RFC2396 compliance and against the URI::Parser Regexp for :PORT.

Can not have a registry or opaque component defined, with a port component defined.

Checks the scheme v component against the URI::Parser Regexp for :SCHEME.

Checks the user v component for RFC2396 compliance and against the URI::Parser Regexp for :USERINFO.

Can not have a registry or opaque component defined, with a user component defined.

Checks the user and password.

If password is not provided, then user is split, using URI::Generic.split_userinfo, to pull user and +password.

See also URI::Generic.check_user, URI::Generic.check_password.

Args

v

URI or String

Description

Attempts to parse other URI oth, returns [parsed_oth, self].

Usage

require 'uri'

uri = URI.parse("http://my.example.com")
uri.coerce("http://foo.com")
#=> [#<URI::HTTP http://foo.com>, #<URI::HTTP http://my.example.com>]

Components of the URI in the order.

Returns an Array of the components defined from the COMPONENT Array.

Returns default port.

No documentation available

Escapes ‘user:password’ v based on RFC 1738 section 3.1.

Returns a proxy URI. The proxy URI is obtained from environment variables such as http_proxy, ftp_proxy, no_proxy, etc. If there is no proper proxy, nil is returned.

If the optional parameter env is specified, it is used instead of ENV.

Note that capitalized variables (HTTP_PROXY, FTP_PROXY, NO_PROXY, etc.) are examined, too.

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.

Checks the fragment v component against the URI::Parser Regexp for :FRAGMENT.

Args

v

String

Description

Public setter for the fragment component v (with validation).

Usage

require 'uri'

uri = URI.parse("http://my.example.com/?id=25#time=1305212049")
uri.fragment = "time=1305212086"
uri.to_s  #=> "http://my.example.com/?id=25#time=1305212086"
No documentation available

Returns true if URI is hierarchical.

Description

URI has components listed in order of decreasing significance from left to right, see RFC3986 tools.ietf.org/html/rfc3986 1.2.3.

Usage

require 'uri'

uri = URI.parse("http://my.example.com/")
uri.hierarchical?
#=> true
uri = URI.parse("mailto:joe@example.com")
uri.hierarchical?
#=> false

Args

v

String

Description

Public setter for the host component v (with validation).

See also URI::Generic.check_host.

Usage

require 'uri'

uri = URI.parse("http://my.example.com")
uri.host = "foo.com"
uri.to_s  #=> "http://foo.com"

Extract the host part of the URI and unwrap brackets for IPv6 addresses.

This method is the same as URI::Generic#host except brackets for IPv6 (and future IP) addresses are removed.

uri = URI("http://[::1]/bar")
uri.hostname      #=> "::1"
uri.host          #=> "[::1]"

Sets the host part of the URI as the argument with brackets for IPv6 addresses.

This method is the same as URI::Generic#host= except the argument can be a bare IPv6 address.

uri = URI("http://foo/bar")
uri.hostname = "::1"
uri.to_s  #=> "http://[::1]/bar"

If the argument seems to be an IPv6 address, it is wrapped with brackets.

No documentation available

Args

oth

URI or String

Description

Merges two URIs.

Usage

require 'uri'

uri = URI.parse("http://my.example.com")
uri.merge("/main.rbx?page=1")
# => "http://my.example.com/main.rbx?page=1"

Args

oth

URI or String

Description

Destructive form of merge.

Usage

require 'uri'

uri = URI.parse("http://my.example.com")
uri.merge!("/main.rbx?page=1")
uri.to_s  # => "http://my.example.com/main.rbx?page=1"

Merges a base path base, with relative path rel, returns a modified base path.

Returns normalized URI.

require 'uri'

URI("HTTP://my.EXAMPLE.com").normalize
#=> #<URI::HTTP http://my.example.com/>

Normalization here means:

  • scheme and host are converted to lowercase,

  • an empty path component is set to “/”.

Destructive version of normalize.

Args

v

String

Description

Public setter for the opaque component v (with validation).

See also URI::Generic.check_opaque.

Returns the parser to be used.

Unless a URI::Parser is defined, DEFAULT_PARSER is used.

Returns the password component.

Args

v

String

Description

Public setter for the password component (with validation).

See also URI::Generic.check_password.

Usage

require 'uri'

uri = URI.parse("http://john:S3nsit1ve@my.example.com")
uri.password = "V3ry_S3nsit1ve"
uri.to_s  #=> "http://john:V3ry_S3nsit1ve@my.example.com"

Args

v

String

Description

Public setter for the path component v (with validation).

See also URI::Generic.check_path.

Usage

require 'uri'

uri = URI.parse("http://my.example.com/pub/files")
uri.path = "/faq/"
uri.to_s  #=> "http://my.example.com/faq/"

Args

v

String

Description

Public setter for the port component v (with validation).

See also URI::Generic.check_port.

Usage

require 'uri'

uri = URI.parse("http://my.example.com")
uri.port = 8080
uri.to_s  #=> "http://my.example.com:8080"

Args

v

String

Description

Public setter for the query component v.

Usage

require 'uri'

uri = URI.parse("http://my.example.com/?id=25")
uri.query = "id=1"
uri.to_s  #=> "http://my.example.com/?id=1"
No documentation available

Returns true if URI does not have a scheme (e.g. http:// or https://) specified.

Replaces self by other URI object.

Args

oth

URI or String

Description

Calculates relative path from oth to self.

Usage

require 'uri'

uri = URI.parse('http://my.example.com/main.rbx?page=1')
uri.route_from('http://my.example.com')
#=> #<URI::Generic /main.rbx?page=1>

Args

oth

URI or String

Description

Calculates relative path to oth from self.

Usage

require 'uri'

uri = URI.parse('http://my.example.com')
uri.route_to('http://my.example.com/main.rbx?page=1')
#=> #<URI::Generic /main.rbx?page=1>

Args

v

String

Description

Public setter for the scheme component v (with validation).

See also URI::Generic.check_scheme.

Usage

require 'uri'

uri = URI.parse("http://my.example.com")
uri.scheme = "https"
uri.to_s  #=> "https://my.example.com"

Args

components

Multiple Symbol arguments defined in URI::HTTP.

Description

Selects specified components from URI.

Usage

require 'uri'

uri = URI.parse('http://myuser:mypass@my.example.com/test.rbx')
uri.select(:userinfo, :host, :path)
# => ["myuser:mypass", "my.example.com", "/test.rbx"]

Protected setter for the host component v.

See also URI::Generic.host=.

Protected setter for the opaque component v.

See also URI::Generic.opaque=.

Protected setter for the password component v.

See also URI::Generic.password=.

Protected setter for the path component v.

See also URI::Generic.path=.

Protected setter for the port component v.

See also URI::Generic.port=.

Protected setter for the scheme component v.

See also URI::Generic.scheme=.

Protected setter for the user component v.

See also URI::Generic.user=.

Protected setter for the user component, and password if available (with validation).

See also URI::Generic.userinfo=.

Returns an Array of the path split on ‘/’.

Returns the userinfo ui as [user, password] if properly formatted as ‘user:password’.

Constructs String from URI.

Returns the user component.

Args

v

String

Description

Public setter for the user component (with validation).

See also URI::Generic.check_user.

Usage

require 'uri'

uri = URI.parse("http://john:S3nsit1ve@my.example.com")
uri.user = "sam"
uri.to_s  #=> "http://sam:V3ry_S3nsit1ve@my.example.com"

Returns the userinfo, either as ‘user’ or ‘user:password’.

Sets userinfo, argument is string like ‘name:pass’.