Class: URI::HTTP
- Inherits:
-
Object
- Object
- URI::HTTP
- Defined in:
- lib/hub/speedy_stdlib.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#fragment ⇒ Object
Returns the value of attribute fragment.
-
#host ⇒ Object
(also: #hostname)
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#path ⇒ Object
Returns the value of attribute path.
- #port ⇒ Object
-
#query ⇒ Object
Returns the value of attribute query.
-
#scheme ⇒ Object
Returns the value of attribute scheme.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #find_proxy ⇒ Object
-
#initialize(str) ⇒ HTTP
constructor
A new instance of HTTP.
- #request_uri ⇒ Object
- #to_s ⇒ Object
- #userinfo ⇒ Object
- #userinfo=(info) ⇒ Object
Constructor Details
#initialize(str) ⇒ HTTP
Returns a new instance of HTTP.
62 63 64 65 66 67 68 69 |
# File 'lib/hub/speedy_stdlib.rb', line 62 def initialize(str) m = str.to_s.match(%r{^ ([\w-]+): // (?:([^/@]+)@)? ([^/?#]+) }x) raise InvalidURIError unless m _, self.scheme, self.userinfo, host = m.to_a self.host, self.port = host.split(':', 2) path, self.fragment = m.post_match.split('#', 2) self.path, self.query = path.to_s.split('?', 2) end |
Instance Attribute Details
#fragment ⇒ Object
Returns the value of attribute fragment.
58 59 60 |
# File 'lib/hub/speedy_stdlib.rb', line 58 def fragment @fragment end |
#host ⇒ Object Also known as: hostname
Returns the value of attribute host.
58 59 60 |
# File 'lib/hub/speedy_stdlib.rb', line 58 def host @host end |
#password ⇒ Object
Returns the value of attribute password.
58 59 60 |
# File 'lib/hub/speedy_stdlib.rb', line 58 def password @password end |
#path ⇒ Object
Returns the value of attribute path.
58 59 60 |
# File 'lib/hub/speedy_stdlib.rb', line 58 def path @path end |
#port ⇒ Object
88 89 90 |
# File 'lib/hub/speedy_stdlib.rb', line 88 def port (@port || (scheme == 'https' ? 443 : 80)).to_i end |
#query ⇒ Object
Returns the value of attribute query.
58 59 60 |
# File 'lib/hub/speedy_stdlib.rb', line 58 def query @query end |
#scheme ⇒ Object
Returns the value of attribute scheme.
58 59 60 |
# File 'lib/hub/speedy_stdlib.rb', line 58 def scheme @scheme end |
#user ⇒ Object
Returns the value of attribute user.
58 59 60 |
# File 'lib/hub/speedy_stdlib.rb', line 58 def user @user end |
Instance Method Details
#find_proxy ⇒ Object
103 104 |
# File 'lib/hub/speedy_stdlib.rb', line 103 def find_proxy end |
#request_uri ⇒ Object
82 83 84 85 86 |
# File 'lib/hub/speedy_stdlib.rb', line 82 def request_uri url = path url += "?#{query}" if query url end |
#to_s ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/hub/speedy_stdlib.rb', line 71 def to_s url = "#{scheme}://" url << "#{userinfo}@" if user || password url << host url << ":#{@port}" if @port url << path url << "?#{query}" if query url << "##{fragment}" if fragment url end |
#userinfo ⇒ Object
97 98 99 100 101 |
# File 'lib/hub/speedy_stdlib.rb', line 97 def userinfo if password then "#{user}:#{password}" elsif user then user end end |
#userinfo=(info) ⇒ Object
92 93 94 95 |
# File 'lib/hub/speedy_stdlib.rb', line 92 def userinfo=(info) self.user, self.password = info.to_s.split(':', 2) info end |