Class: Async::Aws::HttpHandler

Inherits:
Seahorse::Client::Handler
  • Object
show all
Defined in:
lib/async/aws/http_handler.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.client_for(endpoint) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/async/aws/http_handler.rb', line 16

def self.client_for(endpoint)
  clients[endpoint.hostname] ||= ::Async::HTTP::Client.new(
    endpoint,
    retries: 0,
    connection_limit: Async::Aws.connection_limit
  )
end

.clientsObject



4
5
6
# File 'lib/async/aws/http_handler.rb', line 4

def self.clients
  @clients ||= {}
end

.endpoint_for(url) ⇒ Object



12
13
14
# File 'lib/async/aws/http_handler.rb', line 12

def self.endpoint_for(url)
  endpoints[url.to_s] ||= Async::HTTP::Endpoint.parse(url.to_s)
end

.endpointsObject



8
9
10
# File 'lib/async/aws/http_handler.rb', line 8

def self.endpoints
  @endpoints ||= {}
end

Instance Method Details

#call(context) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/async/aws/http_handler.rb', line 24

def call(context)
  req = context.http_request
  resp = context.http_response
  endpoint = self.class.endpoint_for(req.endpoint)

  begin
    client = self.class.client_for(endpoint)
    headers = ::Protocol::HTTP::Headers.new(
      req.headers.reject do |k, v|
        k == 'host' || k == 'content-length'
      end
    )
    buffered_body = Async::HTTP::Body::Buffered.wrap(req.body.read)
    request = ::Protocol::HTTP::Request.new(
      client.scheme, endpoint.authority, req.http_method, endpoint.path,
      nil, headers, buffered_body
    )
    response = client.call(request)
    body = response.read
    resp.signal_headers(response.status.to_i, response.headers.to_h)
    resp.signal_data(body)
    resp.signal_done
  rescue => error
    # not retried
    resp.signal_error(error)
  end

  Seahorse::Client::Response.new(context: context)
end