Class: HTTPkit::Request
- Inherits:
-
Object
- Object
- HTTPkit::Request
- Includes:
- Adamantium, Support::Message
- Defined in:
- lib/httpkit/request.rb
Constant Summary collapse
- SequenceHash =
Class.new(Hash) { include Adamantium::Mutable }
Constants included from Support::Message
Support::Message::CHUNKED, Support::Message::CONTENT_LENGTH, Support::Message::TRANSFER_ENCODING
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#http_version ⇒ Object
readonly
Returns the value of attribute http_version.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #body_included? ⇒ Boolean
- #body_present? ⇒ Boolean
-
#initialize(http_method, uri, headers = {}, body = '', http_version = 1.1) ⇒ Request
constructor
A new instance of Request.
- #new_self(args) ⇒ Object
- #sequence(obj, id = nil) ⇒ Object
- #with(index, argument) ⇒ Object
- #with_body(new_body) ⇒ Object
- #with_headers(new_headers) ⇒ Object
Methods included from Support::Message
#body_headers, build, #close, #closed, #closed!, #closed?, #reject_closed
Constructor Details
#initialize(http_method, uri, headers = {}, body = '', http_version = 1.1) ⇒ Request
Returns a new instance of Request.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/httpkit/request.rb', line 10 def initialize(http_method, uri, headers = {}, body = '', http_version = 1.1) @http_method = http_method # @uri = URI('http://' + uri) @uri = URI.join('http:///', uri).request_uri @headers = headers @body = Body.build(body) @http_version = http_version @sequences = SequenceHash.new end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
8 9 10 |
# File 'lib/httpkit/request.rb', line 8 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
8 9 10 |
# File 'lib/httpkit/request.rb', line 8 def headers @headers end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
8 9 10 |
# File 'lib/httpkit/request.rb', line 8 def http_method @http_method end |
#http_version ⇒ Object (readonly)
Returns the value of attribute http_version.
8 9 10 |
# File 'lib/httpkit/request.rb', line 8 def http_version @http_version end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
8 9 10 |
# File 'lib/httpkit/request.rb', line 8 def uri @uri end |
Instance Method Details
#body_included? ⇒ Boolean
45 46 47 |
# File 'lib/httpkit/request.rb', line 45 def body_included? body_present? end |
#body_present? ⇒ Boolean
49 50 51 |
# File 'lib/httpkit/request.rb', line 49 def body_present? !body.length_known? || !body.length.zero? end |
#new_self(args) ⇒ Object
35 36 37 38 39 |
# File 'lib/httpkit/request.rb', line 35 def new_self(args) other = self.class.new(*args) @sequences.each { |(obj, id)| other.sequence(obj, id) } other end |
#sequence(obj, id = nil) ⇒ Object
41 42 43 |
# File 'lib/httpkit/request.rb', line 41 def sequence(obj, id = nil) @sequences[obj.object_id] ||= id end |
#with(index, argument) ⇒ Object
29 30 31 32 33 |
# File 'lib/httpkit/request.rb', line 29 def with(index, argument) args = [http_method, uri, headers, body, http_version] args[index] = argument new_self(args) end |
#with_body(new_body) ⇒ Object
25 26 27 |
# File 'lib/httpkit/request.rb', line 25 def with_body(new_body) with(3, Body.build(new_body)) end |
#with_headers(new_headers) ⇒ Object
21 22 23 |
# File 'lib/httpkit/request.rb', line 21 def with_headers(new_headers) with(2, headers.merge(new_headers)) end |