Class: AWS::Core::Http::HTTPartyHandler
- Inherits:
-
Object
- Object
- AWS::Core::Http::HTTPartyHandler
- Includes:
- HTTParty
- Defined in:
- lib/aws/core/http/httparty_handler.rb
Overview
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
)
)
Direct Known Subclasses
Defined Under Namespace
Classes: NoOpParser
Instance Attribute Summary collapse
-
#default_request_options ⇒ Hash
readonly
The default options to send to HTTParty on each request.
Instance Method Summary collapse
- #handle(request, response) ⇒ Object
-
#initialize(options = {}) ⇒ HTTPartyHandler
constructor
Constructs a new HTTP handler using HTTParty.
Constructor Details
#initialize(options = {}) ⇒ HTTPartyHandler
Constructs a new HTTP handler using HTTParty.
48 49 50 |
# File 'lib/aws/core/http/httparty_handler.rb', line 48 def initialize = {} @default_request_options = end |
Instance Attribute Details
#default_request_options ⇒ Hash (readonly)
Returns The default options to send to HTTParty on each request.
37 38 39 |
# File 'lib/aws/core/http/httparty_handler.rb', line 37 def @default_request_options end |
Instance Method Details
#handle(request, response) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/aws/core/http/httparty_handler.rb', line 58 def handle(request, response) opts = .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? protocol = 'https' opts[:ssl_ca_file] = request.ssl_ca_file if request.ssl_verify_peer? else protocol = 'http' end url = "#{protocol}://#{request.host}:#{request.port}#{request.uri}" # 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 |