Class: Async::HTTP::Faraday::Adapter

Inherits:
Faraday::Adapter
  • Object
show all
Defined in:
lib/async/http/faraday/adapter.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/async/http/faraday/adapter.rb', line 29

def call(env)
  super
  
  client = HTTP::Client.new(*endpoints_for(env).to_a)
  
  response = client.send(env[:method], env[:url].request_uri, env[:request_headers], env[:body] || [])

  save_response(env, response.status, response.read, response.headers)
  
  @app.call env
end

#endpoints_for(env) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/async/http/faraday/adapter.rb', line 41

def endpoints_for(env)
  return to_enum(:endpoints_for, env) unless block_given?
  
  if url = env[:url]
    yield Async::HTTP::Endpoint.new(url)
  end
end