Class: AWS::Core::Http::Request

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

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRequest

Returns a new empty http request object.



25
26
27
28
29
30
31
32
# 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

Instance Attribute Details

#default_read_timeoutInteger

Returns The number of seconds the service has to respond before a timeout error is raised on the request. Defaults to 60 seconds.

Returns:

  • (Integer)

    The number of seconds the service has to respond before a timeout error is raised on the request. Defaults to 60 seconds.



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

def default_read_timeout
  @default_read_timeout
end

#headersCaseInsensitiveHash

Returns request headers.

Returns:

  • (CaseInsensitiveHash)

    request headers



51
52
53
# File 'lib/aws/core/http/request.rb', line 51

def headers
  @headers
end

#hostString

Returns hostname of the request.

Returns:

  • (String)

    hostname of the request



40
41
42
# File 'lib/aws/core/http/request.rb', line 40

def host
  @host
end

#http_methodString

Returns the HTTP request method (e.g. ‘GET’, ‘PUT’, ‘POST’, ‘HEAD’ or ‘DELETE’). Defaults to ‘POST’.

Returns:

  • (String)

    Returns the HTTP request method (e.g. ‘GET’, ‘PUT’, ‘POST’, ‘HEAD’ or ‘DELETE’). Defaults to ‘POST’.



48
49
50
# File 'lib/aws/core/http/request.rb', line 48

def http_method
  @http_method
end

#portInteger

Returns the port the request will be made over. Defaults to 443 for SSL requests and 80 for non-SSL requests.

Returns:

  • (Integer)

    Returns the port the request will be made over. Defaults to 443 for SSL requests and 80 for non-SSL requests.



44
45
46
# File 'lib/aws/core/http/request.rb', line 44

def port
  @port
end

#proxy_urinil, URI

Returns The URI to the proxy server requests are sent through if configured. Returns nil if there is no proxy.

Returns:

  • (nil, URI)

    The URI to the proxy server requests are sent through if configured. Returns nil if there is no proxy.



79
80
81
# File 'lib/aws/core/http/request.rb', line 79

def proxy_uri
  @proxy_uri
end

#read_timeout=(value) ⇒ Integer

Returns The number of seconds the service has to respond before a timeout error is raised on the request. Defaults to 60 seconds.

Returns:

  • (Integer)

    The number of seconds the service has to respond before a timeout error is raised on the request. Defaults to 60 seconds.



84
85
86
# File 'lib/aws/core/http/request.rb', line 84

def read_timeout=(value)
  @read_timeout = value
end

#regionString

Returns The region name this request is for. Only needs to be populated for requests against signature v4 endpoints.

Returns:

  • (String)

    The region name this request is for. Only needs to be populated for requests against signature v4 endpoints.



58
59
60
# File 'lib/aws/core/http/request.rb', line 58

def region
  @region
end

#service_ruby_nameString

Returns 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).

Returns:

  • (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).



75
76
77
# File 'lib/aws/core/http/request.rb', line 75

def service_ruby_name
  @service_ruby_name
end

#ssl_ca_fileString

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.

Returns:

  • (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.



101
102
103
# File 'lib/aws/core/http/request.rb', line 101

def ssl_ca_file
  @ssl_ca_file
end

#ssl_ca_pathString

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.

Returns:

  • (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.



106
107
108
# File 'lib/aws/core/http/request.rb', line 106

def ssl_ca_path
  @ssl_ca_path
end

#ssl_verify_peerBoolean Also known as: ssl_verify_peer?

Returns true if the client should verify the peer certificate.

Returns:

  • (Boolean)

    Returns true if the client should verify the peer certificate.



94
95
96
# File 'lib/aws/core/http/request.rb', line 94

def ssl_verify_peer
  @ssl_verify_peer
end

#uriString

Returns the request URI (path + querystring).

Returns:

  • (String)

    Returns the request URI (path + querystring).



54
55
56
# File 'lib/aws/core/http/request.rb', line 54

def uri
  @uri
end

#use_sslBoolean Also known as: use_ssl?

Returns true if this request should be made with SSL enabled.

Returns:

  • (Boolean)

    Returns true if this request should be made with SSL enabled.



88
89
90
# File 'lib/aws/core/http/request.rb', line 88

def use_ssl
  @use_ssl
end

Instance Method Details

#bodyString?

Note:

Calling #body on a request with a #body_stream will cause the entire stream to be read into memory.

Returns the request body.

Returns:

  • (String, nil)

    Returns the request body.



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# 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) ⇒ Object

Parameters:

  • body (String)


160
161
162
163
164
165
166
167
# File 'lib/aws/core/http/request.rb', line 160

def body= body
  @body = body
  if body
    headers['content-length'] = body.bytesize if body
  else
    headers.delete('content-length')
  end
end

#body_streamIO?

Returns:

  • (IO, nil)


196
197
198
199
200
201
202
203
204
# 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) ⇒ Object

Note:

You must also set the #headers

Sets the request body as an IO object that will be streamed.

Parameters:

  • stream (IO)

    An object that responds to #read and #eof.



191
192
193
# File 'lib/aws/core/http/request.rb', line 191

def body_stream= stream
  @body_stream = stream
end

#pathString

Returns the HTTP request path.

Returns:

  • (String)

    Returns the HTTP request path.



123
124
125
# File 'lib/aws/core/http/request.rb', line 123

def path
  uri.split(/\?/)[0]
end

#querystringString

Returns the HTTP request querystring.

Returns:

  • (String)

    Returns the HTTP request querystring.



128
129
130
# File 'lib/aws/core/http/request.rb', line 128

def querystring
  uri.split(/\?/)[1]
end