Class: HTTP::Request
- Inherits:
-
Object
- Object
- HTTP::Request
- Defined in:
- lib/http/request.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Method is given as a lowercase symbol e.g.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
-
#uri ⇒ Object
readonly
“Request URI” as per RFC 2616 www.w3.org/Protocols/rfc2616/rfc2616-sec5.html.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#[](header) ⇒ Object
Obtain the given header.
-
#initialize(method, uri, headers = {}, proxy = {}, body = nil, version = "1.1") ⇒ Request
constructor
:nodoc:.
-
#stream(socket) ⇒ Object
Stream the request to a socket.
Constructor Details
#initialize(method, uri, headers = {}, proxy = {}, body = nil, version = "1.1") ⇒ Request
:nodoc:
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/http/request.rb', line 12 def initialize(method, uri, headers = {}, proxy = {}, body = nil, version = "1.1") @method = method.to_s.downcase.to_sym raise UnsupportedMethodError, "unknown method: #{method}" unless METHODS.include? @method @uri = uri.is_a?(URI) ? uri : URI(uri.to_s) @headers = {} headers.each do |name, value| name = name.to_s key = name[CANONICAL_HEADER] key ||= Http.canonicalize_header(name) @headers[key] = value end @proxy, @body, @version = proxy, body, version end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
9 10 11 |
# File 'lib/http/request.rb', line 9 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
9 10 11 |
# File 'lib/http/request.rb', line 9 def headers @headers end |
#method ⇒ Object (readonly)
Method is given as a lowercase symbol e.g. :get, :post
4 5 6 |
# File 'lib/http/request.rb', line 4 def method @method end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
9 10 11 |
# File 'lib/http/request.rb', line 9 def proxy @proxy end |
#uri ⇒ Object (readonly)
“Request URI” as per RFC 2616 www.w3.org/Protocols/rfc2616/rfc2616-sec5.html
8 9 10 |
# File 'lib/http/request.rb', line 8 def uri @uri end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
9 10 11 |
# File 'lib/http/request.rb', line 9 def version @version end |
Instance Method Details
#[](header) ⇒ Object
Obtain the given header
30 31 32 |
# File 'lib/http/request.rb', line 30 def [](header) @headers[Http.canonicalize_header(header)] end |
#stream(socket) ⇒ Object
Stream the request to a socket
35 36 37 38 39 |
# File 'lib/http/request.rb', line 35 def stream(socket) request_header = "#{method.to_s.upcase} #{uri.path} HTTP/#{version}" rs = Http::RequestStream.new socket, body, @headers, request_header rs.stream end |