class AWS::Core::Http::Request

Base class for all service reqeusts. This class describes a basic HTTP request, but will not make one. It is consumed by a HTTP handler class that sends the actual request and parses the actual response.

Attributes

access_key_id[RW]

@return [String] Returns the AWS access key ID used to authorize the

request.

@private

default_read_timeout[RW]

@return [Integer] The number of seconds the service has to respond

before a timeout error is raised on the request.  Defaults to
60 seconds.
headers[RW]

@return [CaseInsensitiveHash] request headers

host[RW]

@return [String] hostname of the request

http_method[RW]

@return [String] Returns the HTTP request method (e.g. 'GET', 'PUT',

'POST', 'HEAD' or 'DELETE').  Defaults to 'POST'.
params[RW]

@return [Array<Param>] Returns an array of request params. Requests

that use signature version 2 add params to the request and then
sign those before building the {#body}.  Normally the {#body}
should be set directly with the HTTP payload.

@private

port[RW]

@return [Integer] Returns the port number this request will be

made via (usually 443 or 80).
proxy_uri[RW]

@return [nil, URI] The URI to the proxy server requests are

sent through if configured.  Returns nil if there is no proxy.
read_timeout[RW]

@return [Integer] The number of seconds the service has to respond

before a timeout error is raised on the request.  Defaults to
60 seconds.
region[RW]

@return [String] The region name this request is for. Only needs

to be populated for requests against signature v4 endpoints.
service_ruby_name[RW]

@return [String] The name of the service for Signature v4 signing.

This does not always match the ruby name (e.g.
simple_email_service and ses do not match).
ssl_ca_file[RW]

@return [String] Returns the path to a bundle of CA certs in PEM

format; the HTTP handler should use this to verify all HTTPS
requests if {#ssl_verify_peer?} is true.
ssl_ca_path[RW]

@return [String] Returns the path to a directory of CA certs.

The HTTP handler should use these to verify all HTTPS
requests if {#ssl_verify_peer?} is true.
ssl_verify_peer[RW]

@return [Boolean] Returns true if the client should verify

the peer certificate.
ssl_verify_peer?[RW]

@return [Boolean] Returns true if the client should verify

the peer certificate.
uri[RW]

@return [String] Returns the request URI (path + querystring).

use_ssl[RW]

@return [Boolean] Returns true if this request should be made

with SSL enabled.
use_ssl?[RW]

@return [Boolean] Returns true if this request should be made

with SSL enabled.

Public Class Methods

new() click to toggle source

Returns a new empty http request object.

# File lib/aws/core/http/request.rb, line 25
def initialize
  @default_read_timeout = 60
  @http_method = 'POST'
  @use_ssl = true
  @headers = CaseInsensitiveHash.new
  @uri = '/'
  @params = []
end

Public Instance Methods

add_param(name_or_param, value = nil) click to toggle source

Adds a request param.

@overload #add_param(param_name, param_value = nil)

Add a param (name/value)
@param [String] param_name
@param [String] param_value Leave blank for sub resources

@overload #add_param(param_obj)

Add a param (object)
@param [Param] param_obj

@private

# File lib/aws/core/http/request.rb, line 144
def add_param name_or_param, value = nil
  if name_or_param.kind_of?(Param)
    @params << name_or_param
  else
    @params << Param.new(name_or_param, value)
  end
end
body() click to toggle source

@note Calling body on a request with a body_stream

will cause the entire stream to be read into memory.

@return [String,nil] Returns the request body.

# File lib/aws/core/http/request.rb, line 172
def body
  if @body
    @body
  elsif @body_stream
    @body = @body_stream.read
    if @body_stream.respond_to?(:rewind)
      @body_stream.rewind
    else
      @body_stream = StringIO.new(@body)
    end
    @body
  else
    nil
  end
end
body=(body) click to toggle source

@param [String] body

# File lib/aws/core/http/request.rb, line 160
def body= body
  @body = body
  if body
    headers['content-length'] = body.size if body
  else
    headers.delete('content-length')
  end
end
body_stream() click to toggle source

@return [IO,nil]

# File lib/aws/core/http/request.rb, line 196
def body_stream
  if @body_stream
    @body_stream
  elsif @body
    StringIO.new(@body)
  else
    nil
  end
end
body_stream=(stream) click to toggle source

Sets the request body as an IO object that will be streamed. @note You must also set the headers['content-length'] @param [IO] stream An object that responds to read and eof.

# File lib/aws/core/http/request.rb, line 191
def body_stream= stream
  @body_stream = stream
end
path() click to toggle source

@return [String] Returns the HTTP request path.

# File lib/aws/core/http/request.rb, line 123
def path
  uri.split(%r\?/)[0]
end
querystring() click to toggle source

@return [String] Returns the HTTP request querystring.

# File lib/aws/core/http/request.rb, line 128
def querystring
  uri.split(%r\?/)[1]
end
url_encoded_params() click to toggle source

@private @return [String,nil] Returns the url encoded request params. If there

are no params, then nil is returned.
# File lib/aws/core/http/request.rb, line 155
def url_encoded_params
  params.empty? ? nil : params.sort.collect(&:encoded).join('&')
end