Class: Celluloid::Http::Response
- Inherits:
-
Object
- Object
- Celluloid::Http::Response
- Extended by:
- Forwardable
- Defined in:
- lib/celluloid-http/response.rb
Constant Summary collapse
- STATUS_CODES =
Rack::Utils::HTTP_STATUS_CODES
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#raw_body ⇒ Object
Returns the value of attribute raw_body.
- #status ⇒ Object
Instance Method Summary collapse
- #body ⇒ Object
- #decoded_body ⇒ Object
- #finished? ⇒ Boolean
-
#initialize(status = nil, headers = {}, body = nil) ⇒ Response
constructor
A new instance of Response.
- #on_body(chunk) ⇒ Object
- #on_headers_complete(headers) ⇒ Object
- #on_message_complete ⇒ Object
- #parser ⇒ Object
- #reason ⇒ Object
- #sym_status ⇒ Object
Constructor Details
#initialize(status = nil, headers = {}, body = nil) ⇒ Response
Returns a new instance of Response.
11 12 13 14 15 |
# File 'lib/celluloid-http/response.rb', line 11 def initialize(status = nil, headers = {}, body = nil) @status, @headers, @body = status, headers, body @raw_body = "" @finished = !!@body end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
9 10 11 |
# File 'lib/celluloid-http/response.rb', line 9 def headers @headers end |
#raw_body ⇒ Object
Returns the value of attribute raw_body.
9 10 11 |
# File 'lib/celluloid-http/response.rb', line 9 def raw_body @raw_body end |
#status ⇒ Object
17 18 19 |
# File 'lib/celluloid-http/response.rb', line 17 def status @status || parser.status_code end |
Instance Method Details
#body ⇒ Object
50 51 52 53 |
# File 'lib/celluloid-http/response.rb', line 50 def body unless finished? @body ||= "" end |
#decoded_body ⇒ Object
55 56 57 |
# File 'lib/celluloid-http/response.rb', line 55 def decoded_body Celluloid::Http::BodyDecoder.decode(headers, raw_body) end |
#finished? ⇒ Boolean
26 27 28 |
# File 'lib/celluloid-http/response.rb', line 26 def finished? @finished end |
#on_body(chunk) ⇒ Object
30 31 32 |
# File 'lib/celluloid-http/response.rb', line 30 def on_body(chunk) @raw_body << chunk end |
#on_headers_complete(headers) ⇒ Object
34 35 36 |
# File 'lib/celluloid-http/response.rb', line 34 def on_headers_complete(headers) @headers = headers end |
#on_message_complete ⇒ Object
21 22 23 24 |
# File 'lib/celluloid-http/response.rb', line 21 def @body = decoded_body @finished = true end |
#parser ⇒ Object
38 39 40 |
# File 'lib/celluloid-http/response.rb', line 38 def parser @parser ||= Http::Parser.new(self) end |
#reason ⇒ Object
42 43 44 |
# File 'lib/celluloid-http/response.rb', line 42 def reason STATUS_CODES[status] end |
#sym_status ⇒ Object
46 47 48 |
# File 'lib/celluloid-http/response.rb', line 46 def sym_status reason.downcase.gsub(/\s|-/, '_').to_sym end |