Class: Readme::HttpResponse

Inherits:
SimpleDelegator
  • Object
show all
Includes:
ContentTypeHelper
Defined in:
lib/readme/http_response.rb

Constant Summary

Constants included from ContentTypeHelper

ContentTypeHelper::JSON_MIME_TYPES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContentTypeHelper

#json?

Class Method Details

.from_parts(status, headers, body) ⇒ Object



9
10
11
# File 'lib/readme/http_response.rb', line 9

def self.from_parts(status, headers, body)
  new(Rack::Response.new(body, status, headers))
end

Instance Method Details

#bodyObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/readme/http_response.rb', line 13

def body
  if raw_body.respond_to?(:rewind)
    raw_body.rewind
    content = raw_body.each.sum('')
    raw_body.rewind

    content
  else
    raw_body.each.sum('')
  end
end

#content_lengthObject



25
26
27
28
29
30
31
32
33
# File 'lib/readme/http_response.rb', line 25

def content_length
  if empty_body_status?
    0
  elsif !headers['Content-Length']
    body.bytesize
  else
    headers['Content-Length'].to_i
  end
end