class HTTP::Response
def chunked?
def chunked? return false unless @headers.include?(Headers::TRANSFER_ENCODING) encoding = @headers.get(Headers::TRANSFER_ENCODING) # TODO: "chunked" is frozen in the request writer. How about making it accessible? encoding.last == "chunked" end
def content_length
-
(Integer)
- otherwise -
(nil)
- if Content-Length was not given, or it's value was invalid
def content_length # http://greenbytes.de/tech/webdav/rfc7230.html#rfc.section.3.3.3 # Clause 3: "If a message is received with both a Transfer-Encoding # and a Content-Length header field, the Transfer-Encoding overrides the Content-Length. return nil if @headers.include?(Headers::TRANSFER_ENCODING) value = @headers[Headers::CONTENT_LENGTH] return nil unless value begin Integer(value) rescue ArgumentError nil end end
def content_type
-
(HTTP::ContentType)
-
def content_type @content_type ||= ContentType.parse headers[Headers::CONTENT_TYPE] end
def cookies
def cookies @cookies ||= headers.each_with_object CookieJar.new do |(k, v), jar| jar.parse(v, uri) if k == Headers::SET_COOKIE end end
def flush
-
(Response)
-
def flush body.to_s self end
def initialize(opts)
(**opts)
-
:uri
(String
) -- -
:body
(String
) -- -
:encoding
(String
) -- Encoding to use when reading body -
:connection
(HTTP::Connection
) -- -
:proxy_headers
(Hash
) -- -
:headers
(Hash
) -- -
:version
(String
) -- HTTP version -
:status
(Integer
) -- Status code
def initialize(opts) @version = opts.fetch(:version) @uri = HTTP::URI.parse(opts.fetch(:uri)) if opts.include? :uri @status = HTTP::Response::Status.new(opts.fetch(:status)) @headers = HTTP::Headers.coerce(opts[:headers] || {}) @proxy_headers = HTTP::Headers.coerce(opts[:proxy_headers] || {}) if opts.include?(:body) @body = opts.fetch(:body) else connection = opts.fetch(:connection) encoding = opts[:encoding] || charset || Encoding::BINARY @body = Response::Body.new(connection, :encoding => encoding) end end
def inspect
def inspect "#<#{self.class}/#{@version} #{code} #{reason} #{headers.to_h.inspect}>" end
def parse(as = nil)
-
(Object)
-
Raises:
-
(HTTP::Error)
- if adapter not found
Parameters:
-
as
(#to_s
) -- Parse as given MIME type
def parse(as = nil) MimeType[as || mime_type].decode to_s end
def to_a
-
(Array(Fixnum, Hash, String))
-
def to_a [status.to_i, headers.to_h, body.to_s] end