Class: Celluloid::Http::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/celluloid-http/response.rb

Constant Summary collapse

STATUS_CODES =
Rack::Utils::HTTP_STATUS_CODES

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#headersObject

Returns the value of attribute headers.



9
10
11
# File 'lib/celluloid-http/response.rb', line 9

def headers
  @headers
end

#raw_bodyObject

Returns the value of attribute raw_body.



9
10
11
# File 'lib/celluloid-http/response.rb', line 9

def raw_body
  @raw_body
end

#statusObject



17
18
19
# File 'lib/celluloid-http/response.rb', line 17

def status
  @status || parser.status_code
end

Instance Method Details

#bodyObject



50
51
52
53
# File 'lib/celluloid-http/response.rb', line 50

def body
  on_message_complete unless finished?
  @body ||= ""
end

#decoded_bodyObject



55
56
57
# File 'lib/celluloid-http/response.rb', line 55

def decoded_body
  Celluloid::Http::BodyDecoder.decode(headers, raw_body)
end

#finished?Boolean

Returns:

  • (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_completeObject



21
22
23
24
# File 'lib/celluloid-http/response.rb', line 21

def on_message_complete
  @body = decoded_body
  @finished = true
end

#parserObject



38
39
40
# File 'lib/celluloid-http/response.rb', line 38

def parser
  @parser ||= Http::Parser.new(self)
end

#reasonObject



42
43
44
# File 'lib/celluloid-http/response.rb', line 42

def reason
  STATUS_CODES[status]
end

#sym_statusObject



46
47
48
# File 'lib/celluloid-http/response.rb', line 46

def sym_status
  reason.downcase.gsub(/\s|-/, '_').to_sym
end