Class: AWS::Core::Http::NetHttpHandler

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ NetHttpHandler

Returns a new instance of NetHttpHandler.



38
39
40
# File 'lib/aws/core/http/net_http_handler.rb', line 38

def initialize options = {}
  @pool = Net::HTTP::ConnectionPool.new(options)
end

Instance Attribute Details

#poolNet::HTTP::ConnectionPool (readonly)

Returns:

  • (Net::HTTP::ConnectionPool)


43
44
45
# File 'lib/aws/core/http/net_http_handler.rb', line 43

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.

Parameters:

Returns:

  • (nil)


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
82
83
84
85
86
87
88
89
# File 'lib/aws/core/http/net_http_handler.rb', line 51

def handle request, response, &read_block

  options = {}
  options[:port] = request.port
  options[:ssl] = request.use_ssl?
  options[:proxy_uri] = request.proxy_uri
  options[:ssl_verify_peer] = request.ssl_verify_peer?
  options[:ssl_ca_file] = request.ssl_ca_file if request.ssl_ca_file
  options[:ssl_ca_path] = request.ssl_ca_path if request.ssl_ca_path

  begin

    connection = pool.connection_for(request.host, options)
    connection.read_timeout = request.read_timeout

    connection.request(build_net_http_request(request)) do |http_resp|
      response.status = http_resp.code.to_i
      response.headers = http_resp.to_hash
      if block_given? and response.status < 300
        http_resp.read_body(&read_block)
      else
        response.body = http_resp.read_body
      end
    end

  # The first rescue clause is required because Timeout::Error is
  # a SignalException (in Ruby 1.8, not 1.9).  Generally, SingalExceptions
  # should not be retried, except for timeout errors.
  rescue Timeout::Error => error
    response.network_error = error
  rescue *PASS_THROUGH_ERRORS => error
    raise error
  rescue Exception => error
    response.network_error = error
  end

  nil

end