Parent

Included Modules

HTTP::Response

Attributes

body[R]
code[R]
status[R]
status_code[R]
uri[R]

Public Class Methods

new(status, version, headers, body, uri = nil) click to toggle source
# File lib/http/response.rb, line 77
def initialize(status, version, headers, body, uri = nil) # rubocop:disable ParameterLists
  @status, @version, @body, @uri = status, version, body, uri
  @headers = HTTP::Headers.coerce(headers || {})
end

Public Instance Methods

charset() click to toggle source

Charset of response (if any) @return [String, nil]

# File lib/http/response.rb, line 118
def charset
  @charset ||= content_type.charset
end
content_type() click to toggle source

Parsed Content-Type header @return [HTTP::ContentType]

# File lib/http/response.rb, line 106
def content_type
  @content_type ||= ContentType.parse headers['Content-Type']
end
flush() click to toggle source

Flushes body and returns self-reference

# File lib/http/response.rb, line 99
def flush
  body.to_s
  self
end
inspect() click to toggle source

Inspect a response

# File lib/http/response.rb, line 133
def inspect
  "#<#{self.class}/#{@version} #{status} #{reason} headers=#{headers.inspect}>"
end
mime_type() click to toggle source

MIME type of response (if any) @return [String, nil]

# File lib/http/response.rb, line 112
def mime_type
  @mime_type ||= content_type.mime_type
end
parse(as = nil) click to toggle source

Parse response body with corresponding MIME type adapter.

@param [to_s] as Parse as given MIME type

instead of the one determined from headers

@raise [Error] if adapter not found @return [Object]

# File lib/http/response.rb, line 128
def parse(as = nil)
  MimeType[as || mime_type].decode to_s
end
reason() click to toggle source

Obtain the ‘Reason-Phrase’ for the response

# File lib/http/response.rb, line 83
def reason
  STATUS_CODES[@status]
end
to_a() click to toggle source

Returns an Array ala Rack: `[status, headers, body]`

# File lib/http/response.rb, line 88
def to_a
  [status, headers.to_h, body.to_s]
end
to_s() click to toggle source

Return the response body as a string

# File lib/http/response.rb, line 93
def to_s
  body.to_s
end
Also aliased as: to_str
to_str() click to toggle source
Alias for: to_s

[Validate]

Generated with the Darkfish Rdoc Generator 2.