Class: AWS::Core::Http::NetHttpHandler
- Inherits:
-
Object
- Object
- AWS::Core::Http::NetHttpHandler
- Defined in:
- lib/aws/core/http/net_http_handler.rb
Overview
NetHttpHandler
This is the default HTTP handler for the aws-sdk gem. It uses Ruby's Net::HTTP to make requests. It uses persistent connections and a connection pool.
Instance Attribute Summary collapse
- #pool ⇒ ConnectionPool readonly
Instance Method Summary collapse
-
#handle(request, response, &read_block) ⇒ nil
Given a populated request object and an empty response object, this method will make the request and them populate the response.
-
#initialize(options = {}) ⇒ ConnectionPool
constructor
Returns a connection pool constructed from the given options.
Constructor Details
#initialize(options = {}) ⇒ ConnectionPool
Returns a connection pool constructed from the given options. Calling this method twice with the same options will return the same pool.
34 35 36 |
# File 'lib/aws/core/http/net_http_handler.rb', line 34 def initialize = {} @pool = ConnectionPool.new() end |
Instance Attribute Details
#pool ⇒ ConnectionPool (readonly)
39 40 41 |
# File 'lib/aws/core/http/net_http_handler.rb', line 39 def pool @pool end |
Instance Method Details
#handle(request, response, &read_block) ⇒ nil
Given a populated request object and an empty response object, this method will make the request and them populate the response.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/aws/core/http/net_http_handler.rb', line 47 def handle request, response, &read_block retry_possible = true begin @pool.session_for(request.endpoint) do |http| http.read_timeout = request.read_timeout http.continue_timeout = request.continue_timeout if http.respond_to?(:continue_timeout=) http.request(build_net_http_request(request)) do |net_http_resp| response.status = net_http_resp.code.to_i response.headers = net_http_resp.to_hash if block_given? and response.status < 300 net_http_resp.read_body do |data| begin yield data ensure retry_possible = false end end else response.body = net_http_resp.read_body end end end rescue *NETWORK_ERRORS => error raise error unless retry_possible response.network_error = error end nil end |