Class: URI::HTTP

Inherits:
Generic show all
Defined in:
lib/uri/http.rb

Overview

The syntax of HTTP URIs is defined in RFC1738 section 3.3.

Note that the Ruby URI library allows HTTP URLs containing usernames and passwords. This is not legal as per the RFC, but used to be supported in Internet Explorer 5 and 6, before the MS04-004 security update. See <URL:support.microsoft.com/kb/834489>.

Direct Known Subclasses

HTTPS

Constant Summary collapse

DEFAULT_PORT =
80
COMPONENT =
[
  :scheme, 
  :userinfo, :host, :port, 
  :path, 
  :query, 
  :fragment
].freeze

Constants inherited from Generic

Generic::USE_REGISTRY

Constants included from REGEXP

REGEXP::ABS_PATH, REGEXP::ABS_URI, REGEXP::ABS_URI_REF, REGEXP::ESCAPED, REGEXP::FRAGMENT, REGEXP::HOST, REGEXP::OPAQUE, REGEXP::PORT, REGEXP::QUERY, REGEXP::REGISTRY, REGEXP::REL_PATH, REGEXP::REL_URI, REGEXP::REL_URI_REF, REGEXP::SCHEME, REGEXP::UNSAFE, REGEXP::URI_REF, REGEXP::USERINFO

Constants included from URI

VERSION, VERSION_CODE

Instance Attribute Summary

Attributes inherited from Generic

#fragment, #host, #opaque, #path, #port, #query, #registry, #scheme

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Generic

#==, #absolute?, build2, #coerce, component, #component, #default_port, default_port, #eql?, #hash, #hierarchical?, #inspect, #merge, #merge!, #normalize, #normalize!, #password, #password=, #relative?, #route_from, #route_to, #select, #to_s, use_registry, #user, #user=, #userinfo, #userinfo=

Methods included from URI

extract, join, parse, regexp, split

Methods included from Escape

#escape, #unescape

Constructor Details

#initialize(*arg) ⇒ HTTP

Description

Create a new URI::HTTP object from generic URI components as per RFC 2396. No HTTP-specific syntax checking (as per RFC 1738) is performed.

Arguments are scheme, userinfo, host, port, registry, path, opaque, query and fragment, in that order.

Example:

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


77
78
79
# File 'lib/uri/http.rb', line 77

def initialize(*arg)
  super(*arg)
end

Class Method Details

.build(args) ⇒ Object

Description

Create 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:

newuri = URI::HTTP.build({:host => 'www.example.com', 
  :path> => '/foo/bar'})

newuri = 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.



57
58
59
60
# File 'lib/uri/http.rb', line 57

def self.build(args)
  tmp = Util::make_components_hash(self, args)
  return super(tmp)
end

Instance Method Details

#request_uriObject

Description

Returns the full path for an HTTP request, as required by Net::HTTP::Get.

If the URI contains a query, the full path is URI#path + '?' + URI#query. Otherwise, the path is simply URI#path.



89
90
91
92
93
94
95
96
# File 'lib/uri/http.rb', line 89

def request_uri
  r = path_query
  if r[0] != ?/
    r = '/' + r
  end

  r
end