Module: HttpClient::Mixin::Response

Included in:
RawResponse, Response
Defined in:
lib/http_client/mixin/response.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#net_http_resObject (readonly)

Returns the value of attribute net_http_res.



4
5
6
# File 'lib/http_client/mixin/response.rb', line 4

def net_http_res
  @net_http_res
end

Class Method Details

.included(receiver) ⇒ Object



29
30
31
# File 'lib/http_client/mixin/response.rb', line 29

def self.included(receiver)
  receiver.extend(HttpClient::Mixin::Response::ClassMethods)
end

Instance Method Details

#codeObject

HTTP status code, always 200 since HttpClient throws exceptions for other codes.



8
9
10
# File 'lib/http_client/mixin/response.rb', line 8

def code
  @code ||= @net_http_res.code.to_i
end

#cookiesObject

Hash of cookies extracted from response headers



19
20
21
22
23
24
25
26
27
# File 'lib/http_client/mixin/response.rb', line 19

def cookies
  @cookies ||= (self.headers[:set_cookie] || "").split('; ').inject({}) do |out, raw_c|
    key, val = raw_c.split('=')
    unless %w(expires domain path secure).member?(key)
      out[key] = val
    end
    out
  end
end

#headersObject

A hash of the headers, beautified with symbols and underscores. e.g. “Content-type” will become :content_type.



14
15
16
# File 'lib/http_client/mixin/response.rb', line 14

def headers
  @headers ||= self.class.beautify_headers(@net_http_res.to_hash)
end