Class: HT2P::Client::Response
- Inherits:
-
Object
- Object
- HT2P::Client::Response
- Extended by:
- Forwardable
- Defined in:
- lib/ht2p/client/response.rb
Defined Under Namespace
Classes: Chunked, Empty, Transfer
Constant Summary collapse
- HAS_BODY =
[:get, :post, :put, :delete, :trace]
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#header ⇒ Object
(also: #headers)
readonly
Returns the value of attribute header.
Instance Method Summary collapse
-
#initialize(client) ⇒ Response
constructor
A new instance of Response.
- #read(length = nil) ⇒ Object
- #receive(&block) ⇒ Object
Constructor Details
#initialize(client) ⇒ Response
Returns a new instance of Response.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ht2p/client/response.rb', line 11 def initialize(client) @client, @code, @header = client, *HT2P::Header.load(client) @body = if HAS_BODY.include? @client.request.method.to_s.downcase.to_sym if @header['transfer-encoding'].to_s.downcase == 'chunked' Chunked.new @client else Transfer.new @client, @header['content-length'].to_i end else Empty.new end end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
5 6 7 |
# File 'lib/ht2p/client/response.rb', line 5 def code @code end |
#header ⇒ Object (readonly) Also known as: headers
Returns the value of attribute header.
5 6 7 |
# File 'lib/ht2p/client/response.rb', line 5 def header @header end |
Instance Method Details
#read(length = nil) ⇒ Object
33 34 35 |
# File 'lib/ht2p/client/response.rb', line 33 def read(length=nil) @body.read length end |
#receive(&block) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/ht2p/client/response.rb', line 25 def receive(&block) if block_given? block.call self else read end end |