You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: AWS::Core::Http::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/core/http/response.rb

Overview

Represents the http response from a service request.

Responses have:

  • status (200, 404, 500, etc)
  • headers (hash of response headers)
  • body (the response body)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Response

Returns a new instance of Response

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :status (Integer) — default: 200

    HTTP status code

  • :headers (Hash) — default: {}

    HTTP response headers

  • :body (String) — default: ''

    HTTP response body

Yields:

  • (_self)

Yield Parameters:



53
54
55
56
57
58
59
# File 'lib/aws/core/http/response.rb', line 53

def initialize options = {}, &block
  @status = options[:status] || 200
  @headers = options[:headers] || {}
  @body = options[:body]
  yield(self) if block_given?
  self
end

Instance Attribute Details

#bodyString?

Returns the HTTP response body.

Returns:

  • (String, nil)

    Returns the HTTP response body.



34
35
36
# File 'lib/aws/core/http/response.rb', line 34

def body
  @body
end

#headersHash

Returns ({}) Returns the HTTP response headers.

Returns:

  • (Hash)

    ({}) Returns the HTTP response headers.



31
32
33
# File 'lib/aws/core/http/response.rb', line 31

def headers
  @headers
end

#network_errorException?

Returns:

  • (Exception, nil)


37
38
39
# File 'lib/aws/core/http/response.rb', line 37

def network_error
  @network_error
end

#statusInteger

Returns the http response status code.

Returns:

  • (Integer)

    Returns the http response status code.



28
29
30
# File 'lib/aws/core/http/response.rb', line 28

def status
  @status
end

Instance Method Details

#header(name) ⇒ String?

Returns the header value with the given name.

The value is matched case-insensitively so if the headers hash contains a key like 'Date' and you request the value for 'date' the 'Date' value will be returned.

Parameters:

  • name (String, Symbol)

    The name of the header to fetch a value for.

Returns:

  • (String, nil)

    The value of the given header



69
70
71
72
73
74
75
76
# File 'lib/aws/core/http/response.rb', line 69

def header name
  headers.each_pair do |header_name, header_value|
    if header_name.downcase == name.to_s.downcase
      return header_value.is_a?(Array) ? header_value.first : header_value
    end
  end
  nil
end

#network_error?Boolean

Returns true if the request could not be made because of a networking issue (including timeouts).

Returns:

  • (Boolean)

    Returns true if the request could not be made because of a networking issue (including timeouts).



41
42
43
# File 'lib/aws/core/http/response.rb', line 41

def network_error?
  @network_error ? true : false
end