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.



27
28
29
30
31
32
33
34
# File 'lib/aws/core/http/request.rb', line 27

def initialize
  @http_method = 'POST'
  @use_ssl = true
  @headers = CaseInsensitiveHash.new
  @uri = '/'
  @params = []
  @read_timeout = 60
end

Instance Attribute Details

#headersCaseInsensitiveHash



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

def headers
  @headers
end

#hostString



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

def host
  @host
end

#http_methodString



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

def http_method
  @http_method
end

#portInteger



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

def port
  @port
end

#read_timeoutInteger Also known as: default_read_timeout



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

def read_timeout
  @read_timeout
end

#regionString



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

def region
  @region
end

#service_ruby_nameString



72
73
74
# File 'lib/aws/core/http/request.rb', line 72

def service_ruby_name
  @service_ruby_name
end

#uriString



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

def uri
  @uri
end

#use_sslBoolean Also known as: use_ssl?



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

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.



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/aws/core/http/request.rb', line 157

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



145
146
147
148
149
150
151
152
# File 'lib/aws/core/http/request.rb', line 145

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

#body_streamIO?



181
182
183
184
185
186
187
188
189
# File 'lib/aws/core/http/request.rb', line 181

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['content-length']

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



176
177
178
# File 'lib/aws/core/http/request.rb', line 176

def body_stream= stream
  @body_stream = stream
end

#endpointObject



92
93
94
95
96
97
98
99
# File 'lib/aws/core/http/request.rb', line 92

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

#pathString



108
109
110
# File 'lib/aws/core/http/request.rb', line 108

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

#querystringString



113
114
115
# File 'lib/aws/core/http/request.rb', line 113

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