# 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
Charset of response (if any) @return [String, nil]
# File lib/http/response.rb, line 118 def charset @charset ||= content_type.charset end
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
Flushes body and returns self-reference
# File lib/http/response.rb, line 99 def flush body.to_s self end
Inspect a response
# File lib/http/response.rb, line 133 def inspect "#<#{self.class}/#{@version} #{status} #{reason} headers=#{headers.inspect}>" end
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 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
Obtain the ‘Reason-Phrase’ for the response
# File lib/http/response.rb, line 83 def reason STATUS_CODES[@status] end
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
Return the response body as a string
# File lib/http/response.rb, line 93 def to_s body.to_s end
Generated with the Darkfish Rdoc Generator 2.