Method: HTTP::Response#initialize

Defined in:
lib/http/response.rb

#initialize(opts) ⇒ Response

Inits a new instance

Parameters:

  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • :status (Integer)

    Status code

  • :version (String)

    HTTP version

  • :headers (Hash)
  • :proxy_headers (Hash)
  • :connection (HTTP::Connection)
  • :encoding (String)

    Encoding to use when reading body

  • :body (String)
  • request (HTTP::Request)

    The request this is in response to.

  • :uri (String) — default: DEPRECATED

    used to populate a missing request



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/http/response.rb', line 46

def initialize(opts)
  @version       = opts.fetch(:version)
  @request       = init_request(opts)
  @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 || default_encoding

    @body = Response::Body.new(connection, encoding: encoding)
  end
end