class HTTP::URI
def self.form_encode(form_values, sort = false)
-
(String)- encoded value
Parameters:
-
sort(TrueClass, FalseClass) -- should key/value pairs be sorted first? -
form_values(#to_hash, #to_ary) -- to encode
def self.form_encode(form_values, sort = false) Addressable::URI.form_encode(form_values, sort) end
def self.parse(uri)
-
(HTTP::URI)- new URI instance
Parameters:
-
uri(HTTP::URI, String, #to_str) -- to parse
def self.parse(uri) return uri if uri.is_a?(self) new(Addressable::URI.parse(uri)) end
def self.percent_encode(string)
- Private: -
Returns:
-
(String)- encoded value
Parameters:
-
string(String) -- raw string
def self.percent_encode(string) string&.gsub(PERCENT_ENCODE) do |substr| substr.encode(Encoding::UTF_8).bytes.map { |c| format("%%%02X", c) }.join end end
def ==(other)
-
(TrueClass, FalseClass)- are the URIs equivalent (after normalization)?
Parameters:
-
other(Object) -- URI to compare this one with
def ==(other) other.is_a?(URI) && normalize.to_s == other.normalize.to_s end
def dup
-
(Object)- duplicated URI
def dup self.class.new @uri.dup end
def eql?(other)
-
(TrueClass, FalseClass)- are the URIs equivalent?
Parameters:
-
other(Object) -- URI to compare this one with
def eql?(other) other.is_a?(URI) && to_s == other.to_s end
def hash
-
(Integer)- A hash of the URI
def hash @hash ||= to_s.hash * -1 end
def host=(new_host)
-
(void)-
Parameters:
-
new_host(String, #to_str) -- The new host component.
def host=(new_host) @uri.host = process_ipv6_brackets(new_host, :brackets => true) @host = process_ipv6_brackets(@uri.host) @normalized_host = process_ipv6_brackets(@uri.normalized_host) end
def http?
-
(False)- otherwise -
(True)- if URI is HTTP
def http? HTTP_SCHEME == scheme end
def https?
-
(False)- otherwise -
(True)- if URI is HTTPS
def https? HTTPS_SCHEME == scheme end
def initialize(options_or_uri = {})
-
(HTTP::URI)- new URI instance
Options Hash:
(**options_or_uri)-
:fragment(String, #to_str) -- component at the end of the URI -
:query(String, #to_str) -- component distinct from path -
:path(String, #to_str) -- component to request -
:port(String, #to_str) -- network port to connect to -
:host(String, #to_str) -- name component -
:password(String, #to_str) -- for basic authentication -
:user(String, #to_str) -- for basic authentication -
:scheme(String, #to_str) -- URI scheme
Parameters:
-
options_or_uri(Hash, Addressable::URI) --
def initialize(options_or_uri = {}) case options_or_uri when Hash @uri = Addressable::URI.new(options_or_uri) when Addressable::URI @uri = options_or_uri else raise TypeError, "expected Hash for options, got #{options_or_uri.class}" end @host = process_ipv6_brackets(@uri.host) @normalized_host = process_ipv6_brackets(@uri.normalized_host) end
def inspect
-
(String)- human-readable representation of URI
def inspect format("#<%s:0x%014x URI:%s>", self.class.name, object_id << 1, to_s) end
def port
-
(Integer)- port number
def port @uri.port || @uri.default_port end
def process_ipv6_brackets(raw_host, brackets: false)
-
(String)- Host with IPv6 address brackets added or removed
Parameters:
-
brackets(Boolean) -- When true, brackets will be added to IPv6 addresses if missing. When
def process_ipv6_brackets(raw_host, brackets: false) ip = IPAddr.new(raw_host) if ip.ipv6? brackets ? "[#{ip}]" : ip.to_s else raw_host end rescue IPAddr::Error raw_host end
def to_s
-
(String)- URI serialized as a String
def to_s @uri.to_s end