Class: HTTP::Response

### Home Classes Methods

### In Files

- lib/http/response.rb
- lib/http/response/body.rb
- lib/http/response/caching.rb
- lib/http/response/io_body.rb
- lib/http/response/parser.rb
- lib/http/response/status.rb
- lib/http/response/status/reasons.rb
- lib/http/response/string_body.rb

### Parent

Object

### Namespace

- CLASS HTTP::Response::Body
- CLASS HTTP::Response::Caching
- CLASS HTTP::Response::IoBody
- CLASS HTTP::Response::Parser
- CLASS HTTP::Response::Status
- CLASS HTTP::Response::StringBody

### Methods

- ::new
- #caching
- #charset
- #content_type
- #cookies
- #flush
- #inspect
- #mime_type
- #parse
- #to_a

### Included Modules

- HTTP::Headers::Mixin

### Class/Module Index

Quicksearch

- HTTP
- HTTP::Cache
- HTTP::Cache::Headers
- HTTP::Cache::NullCache
- HTTP::Cache::NullLogger
- HTTP::CacheError
- HTTP::Chainable
- HTTP::Client
- HTTP::Connection
- HTTP::Error
- HTTP::Headers
- HTTP::Headers::Mixin
- HTTP::InvalidHeaderNameError
- HTTP::MimeType
- HTTP::MimeType::Adapter
- HTTP::MimeType::JSON
- HTTP::Options
- HTTP::Redirector
- HTTP::Redirector::EndlessRedirectError
- HTTP::Redirector::TooManyRedirectsError
- HTTP::Request
- HTTP::Request::Caching
- HTTP::Request::UnsupportedMethodError
- HTTP::Request::UnsupportedSchemeError
- HTTP::Request::Writer
- HTTP::RequestError
- HTTP::Response
- HTTP::Response::Body
- HTTP::Response::Caching
- HTTP::Response::IoBody
- HTTP::Response::Parser
- HTTP::Response::Status
- HTTP::Response::StringBody
- HTTP::ResponseError
- HTTP::StateError
- HTTP::Timeout
- HTTP::Timeout::Global
- HTTP::Timeout::Null
- HTTP::Timeout::PerOperation
- HTTP::TimeoutError
- HTTP::URI
- Object

No matching classes.

# HTTP::Response

### Constants

STATUS_CODES

  @deprecated Will be removed in 1.0.0

      Use Status::REASONS

SYMBOL_TO_STATUS_CODE

  @deprecated Will be removed in 1.0.0

### Attributes

body[R]

@return [Body]

status[R]

@return [Status]

uri[R]

@return [URI, nil]

### Public Class Methods

new(status, version, headers, body, uri = nil) click to toggle source

    # File lib/http/response.rb, line 34
    def initialize(status, version, headers, body, uri = nil) # rubocop:disable ParameterLists
      @version = version
      @body    = body
      @uri     = uri && HTTP::URI.parse(uri)
      @status  = HTTP::Response::Status.new status
      @headers = HTTP::Headers.coerce(headers || {})
    end

### Public Instance Methods

caching() click to toggle source

@return [HTTP::Response::Caching]

    # File lib/http/response.rb, line 120
    def caching
      Caching.new self
    end

charset() click to toggle source

Charset of response (if any)

@return [String, nil]

    # File lib/http/response.rb, line 94
    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 80
    def content_type
      @content_type ||= ContentType.parse headers[Headers::CONTENT_TYPE]
    end

cookies() click to toggle source

    # File lib/http/response.rb, line 98
    def cookies
      @cookies ||= headers.each_with_object CookieJar.new do |(k, v), jar|
        jar.parse(v, uri) if k == Headers::SET_COOKIE
      end
    end

flush() click to toggle source

Flushes body and returns self-reference

@return [Response]

    # File lib/http/response.rb, line 72
    def flush
      body.to_s
      self
    end

inspect() click to toggle source

Inspect a response

    # File lib/http/response.rb, line 115
    def inspect
      "#<#{self.class}/#{@version} #{code} #{reason} #{headers.to_h.inspect}>"
    end

mime_type() click to toggle source

MIME type of response (if any)

@return [String, nil]

    # File lib/http/response.rb, line 87
    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 110
    def parse(as = nil)
      MimeType[as || mime_type].decode to_s
    end

to_a() click to toggle source

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

@return [Array(Fixnum, Hash, String)]

    # File lib/http/response.rb, line 65
    def to_a
      [status.to_i, headers.to_h, body.to_s]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.