Class: AWS::Core::Http::Request
- Inherits:
-
Object
- Object
- AWS::Core::Http::Request
- 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
-
#default_read_timeout ⇒ Integer
The number of seconds the service has to respond before a timeout error is raised on the request.
-
#headers ⇒ CaseInsensitiveHash
Request headers.
-
#host ⇒ String
Hostname of the request.
-
#http_method ⇒ String
Returns the HTTP request method (e.g. 'GET', 'PUT', 'POST', 'HEAD' or 'DELETE').
-
#port ⇒ Integer
Returns the port the request will be made over.
-
#read_timeout ⇒ Integer
writeonly
The number of seconds the service has to respond before a timeout error is raised on the request.
-
#region ⇒ String
The region name this request is for.
-
#service_ruby_name ⇒ String
The name of the service for Signature v4 signing.
-
#uri ⇒ String
Returns the request URI (path + querystring).
-
#use_ssl ⇒ Boolean
(also: #use_ssl?)
Returns
true
if this request should be made with SSL enabled.
Instance Method Summary collapse
-
#body ⇒ String?
Returns the request body.
- #body=(body) ⇒ Object
- #body_stream ⇒ IO?
-
#body_stream=(stream) ⇒ Object
Sets the request body as an IO object that will be streamed.
- #endpoint ⇒ Object
-
#initialize ⇒ Request
constructor
Returns a new empty http request object.
-
#path ⇒ String
Returns the HTTP request path.
-
#querystring ⇒ String
Returns the HTTP request querystring.
Constructor Details
#initialize ⇒ Request
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_timeout ⇒ Integer
Returns 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 |
#headers ⇒ CaseInsensitiveHash
Returns request headers.
51 52 53 |
# File 'lib/aws/core/http/request.rb', line 51 def headers @headers end |
#host ⇒ String
Returns hostname of the request.
40 41 42 |
# File 'lib/aws/core/http/request.rb', line 40 def host @host end |
#http_method ⇒ 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 |
#port ⇒ 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 |
#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.
80 81 82 |
# File 'lib/aws/core/http/request.rb', line 80 def read_timeout=(value) @read_timeout = value end |
#region ⇒ String
Returns 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_name ⇒ String
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).
75 76 77 |
# File 'lib/aws/core/http/request.rb', line 75 def service_ruby_name @service_ruby_name end |
#uri ⇒ String
Returns the request URI (path + querystring).
54 55 56 |
# File 'lib/aws/core/http/request.rb', line 54 def uri @uri end |
#use_ssl ⇒ Boolean Also known as: use_ssl?
Returns true
if this request should be made
with SSL enabled.
84 85 86 |
# File 'lib/aws/core/http/request.rb', line 84 def use_ssl @use_ssl end |
Instance Method Details
#body ⇒ String?
Calling #body on a request with a #body_stream will cause the entire stream to be read into memory.
Returns the request body.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/aws/core/http/request.rb', line 166 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
154 155 156 157 158 159 160 161 |
# File 'lib/aws/core/http/request.rb', line 154 def body= body @body = body if body headers['content-length'] = body.bytesize if body else headers.delete('content-length') end end |
#body_stream ⇒ IO?
190 191 192 193 194 195 196 197 198 |
# File 'lib/aws/core/http/request.rb', line 190 def body_stream if @body_stream @body_stream elsif @body StringIO.new(@body) else nil end end |
#body_stream=(stream) ⇒ Object
You must also set the #headers['content-length']
Sets the request body as an IO object that will be streamed.
185 186 187 |
# File 'lib/aws/core/http/request.rb', line 185 def body_stream= stream @body_stream = stream end |
#endpoint ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/aws/core/http/request.rb', line 93 def endpoint scheme = use_ssl ? 'https' : 'http' port = case scheme when 'https' then self.port == 443 ? '' : ":#{self.port}" when 'http' then self.port == 80 ? '' : ":#{self.port}" end "#{scheme}://#{host}#{port}" end |
#path ⇒ String
Returns the HTTP request path.
117 118 119 |
# File 'lib/aws/core/http/request.rb', line 117 def path uri.split(/\?/)[0] end |
#querystring ⇒ String
Returns the HTTP request querystring.
122 123 124 |
# File 'lib/aws/core/http/request.rb', line 122 def querystring uri.split(/\?/)[1] end |