module URI

Constants

Error
InvalidComponentError
InvalidURIError

Public Class Methods

===(other) click to toggle source
# File lib/hub/speedy_stdlib.rb, line 67
def self.===(other)
  other.respond_to?(:host)
end
encode_www_form(params) click to toggle source
# File lib/hub/speedy_stdlib.rb, line 56
def self.encode_www_form(params)
  params.map { |k, v|
    if v.class == Array
      encode_www_form(v.map { |x| [k, x] })
    else
      ek = CGI.escape(k)
      v.nil? ? ek : "#{ek}=#{CGI.escape(v)}"
    end
  }.join("&")
end
parse(str) click to toggle source
# File lib/hub/speedy_stdlib.rb, line 40
def self.parse(str)
  m = str.to_s.match(%r{^ ([\w-]+): // (?:([^/@]+)@)? ([^/?#]+) }x)
  raise InvalidURIError unless m

  _, scheme, userinfo, host = m.to_a
  default_port = scheme == 'https' ? 443 : 80
  host, port = host.split(':', 2)
  port = port ? port.to_i : default_port

  path, fragment = m.post_match.split('#', 2)
  path, query = path.split('?', 2) if path
  path = path.to_s

  URI::HTTP.new(scheme, userinfo, host, port, nil, path, nil, query, fragment)
end