Skip to content
class method

URI::HTTP.build

(::Array[::String | ::Integer] args) -> instance
({ userinfo: ::String?, host: ::String?, port: ::Integer?, path: ::String?, query: ::String?, fragment: ::String? }) -> instance
build(args)

Description

Creates a new URI::HTTP object from components, with syntax checking.

The components accepted are userinfo, host, port, path, query, and fragment.

The components should be provided either as an Array, or as a Hash with keys formed by preceding the component names with a colon.

If an Array is used, the components must be passed in the order [userinfo, host, port, path, query, fragment].

Example:

Example
uri = URI::HTTP.build(host: 'www.example.com', path: '/foo/bar')

uri = URI::HTTP.build([nil, "www.example.com", nil, "/path",
  "query", 'fragment'])

Currently, if passed userinfo components this method generates invalid HTTP URIs as per RFC 1738.

See also #authority #check_host also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0