Module: URI
- Defined in:
- lib/hub/speedy_stdlib.rb
Defined Under Namespace
Classes: HTTP
Constant Summary collapse
- Error =
Class.new(StandardError)
- InvalidURIError =
Class.new(Error)
- InvalidComponentError =
Class.new(Error)
Class Method Summary collapse
Class Method Details
.===(other) ⇒ Object
67 68 69 |
# File 'lib/hub/speedy_stdlib.rb', line 67 def self.===(other) other.respond_to?(:host) end |
.encode_www_form(params) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# 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) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# 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 |