class Readme::HttpResponse

Public Class Methods

from_parts(status, headers, body) click to toggle source
# File lib/readme/http_response.rb, line 9
def self.from_parts(status, headers, body)
  new(Rack::Response.new(body, status, headers))
end

Public Instance Methods

body() click to toggle source
# File lib/readme/http_response.rb, line 13
def body
  if raw_body.respond_to?(:rewind)
    raw_body.rewind
    content = raw_body.each.reduce("", :+)
    raw_body.rewind

    content
  else
    raw_body.each.reduce("", :+)
  end
end
content_length() click to toggle source
# 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

Private Instance Methods

empty_body_status?() click to toggle source
# File lib/readme/http_response.rb, line 41
def empty_body_status?
  Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include?(status.to_i)
end
raw_body() click to toggle source
# File lib/readme/http_response.rb, line 37
def raw_body
  __getobj__.body
end