Makes HTTP requests using HTTParty. This is the default handler, so you don’t need to do anything special to configure it. However, you can directly instantiate this class in order to send extra options to HTTParty, for example to enable an HTTP proxy:
AWS.config( :http_handler => AWS::Http::HTTPartyHandler.new( :http_proxyaddr => "http://myproxy.com", :http_proxyport => 80 ) )
@return [Hash] The default options to send to HTTParty on each
request.
Constructs a new HTTP handler using HTTParty.
@param [Hash] options Default options to send to HTTParty on
each request. These options will be sent to +get+, +post+, +head+, +put+, or +delete+ when a request is made. Note that +:body+, +:headers+, +:parser+, and +:ssl_ca_file+ are ignored. If you need to set the CA file, you should use the +:ssl_ca_file+ option to {AWS.config} or {Configuration} instead.
# File lib/aws/core/http/httparty_handler.rb, line 48 def initialize options = {} @default_request_options = options end
# File lib/aws/core/http/httparty_handler.rb, line 58 def handle(request, response) opts = default_request_options.merge({ :body => request.body, :parser => NoOpParser }) if request.proxy_uri opts[:http_proxyaddr] = request.proxy_uri.host opts[:http_proxyport] = request.proxy_uri.port end if request.use_ssl? url = "https://#{request.host}:443#{request.uri}" opts[:ssl_ca_file] = request.ssl_ca_file if request.ssl_verify_peer? else url = "http://#{request.host}#{request.uri}" end # get, post, put, delete, head method = request.http_method.downcase # Net::HTTP adds this header for us when the body is # provided, but it messes up signing headers = { 'content-type' => '' } # headers must have string values (net http calls .strip on them) request.headers.each_pair do |key,value| headers[key] = value.to_s end opts[:headers] = headers begin http_response = self.class.send(method, url, opts) rescue Timeout::Error, Errno::ETIMEDOUT => e response.timeout = true else response.body = http_response.body response.status = http_response.code.to_i response.headers = http_response.to_hash end end