Parent

Typhoeus::Response

Attributes

app_connect_time[R]
body[R]
code[R]
connect_time[R]
curl_error_message[R]
curl_return_code[R]
effective_url[R]
headers[R]
headers_hash[W]
mock[RW]
name_lookup_time[R]
pretransfer_time[R]
primary_ip[R]
request[RW]
requested_http_method[R]
requested_remote_method[R]
requested_url[R]
start_time[R]
start_transfer_time[R]
time[R]

Public Class Methods

new(params = {}) click to toggle source
# File lib/typhoeus/response.rb, line 15
def initialize(params = {})
  @code                  = params[:code]
  @curl_return_code      = params[:curl_return_code]
  @curl_error_message    = params[:curl_error_message]
  @status_message        = params[:status_message]
  @http_version          = params[:http_version]
  @headers               = params[:headers]
  @body                  = params[:body]
  @time                  = params[:time]
  @requested_url         = params[:requested_url]
  @requested_http_method = params[:requested_http_method]
  @start_time            = params[:start_time]
  @start_transfer_time   = params[:start_transfer_time]
  @app_connect_time      = params[:app_connect_time]
  @pretransfer_time      = params[:pretransfer_time]
  @connect_time          = params[:connect_time]
  @name_lookup_time      = params[:name_lookup_time]
  @request               = params[:request]
  @effective_url         = params[:effective_url]
  @primary_ip            = params[:primary_ip]
  @mock                  = params[:mock] || false  # default
  @headers_hash          = NormalizedHeaderHash.new(params[:headers_hash]) if params[:headers_hash]
end

Public Instance Methods

headers_hash() click to toggle source
# File lib/typhoeus/response.rb, line 48
def headers_hash
  @headers_hash ||= begin
    headers.split("\n").map {|o| o.strip}.inject(Typhoeus::NormalizedHeaderHash.new) do |hash, o|
      if o.empty? || o =~ /^HTTP\/[\d\.]+/
        hash
      else
        i = o.index(":") || o.size
        key = o.slice(0, i)
        value = o.slice(i + 1, o.size)
        value = value.strip unless value.nil?
        if hash.has_key? key
          hash[key] = [hash[key], value].flatten
        else
          hash[key] = value
        end

        hash
      end
    end
  end
end
http_version() click to toggle source
# File lib/typhoeus/response.rb, line 87
def http_version
  @http_version ||= first_header_line ? first_header_line[/HTTP\/(\S+)/, 1] : nil
end
mock?() click to toggle source

Returns true if this is a mock response.

# File lib/typhoeus/response.rb, line 40
def mock?
  @mock
end
modified?() click to toggle source
# File lib/typhoeus/response.rb, line 95
def modified?
  @code != 304
end
status_message() click to toggle source
# File lib/typhoeus/response.rb, line 70
def status_message
  return @status_message if @status_message != nil

  # HTTP servers can choose not to include the explanation to HTTP codes. The RFC
  # states this (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4):
  # Except when responding to a HEAD request, the server SHOULD include an entity containing
  # an explanation of the error situation [...]
  # This means 'HTTP/1.1 404' is as valid as 'HTTP/1.1 404 Not Found' and we have to handle it.

  # Regexp doc: http://rubular.com/r/eAr1oVYsVa
  if first_header_line != nil and first_header_line[/\d{3} (.*)$/, 1] != nil
    @status_message = first_header_line[/\d{3} (.*)$/, 1].chomp
  else
    @status_message = nil
  end
end
success?() click to toggle source
# File lib/typhoeus/response.rb, line 91
def success?
  @code >= 200 && @code < 300
end
timed_out?() click to toggle source
# File lib/typhoeus/response.rb, line 99
def timed_out?
  curl_return_code == 28
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.