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.body.read, response.headers, response.reason)
  
  @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::URLEndpoint.new(url)
  end
end

#ssl_context_for(options) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/async/http/faraday/adapter.rb', line 49

def ssl_context_for(options)
  OpenSSL::SSL::SSLContext.new.tap do |context|
    context.set_params(
      verify_mode: options.fetch(:verify, true) ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE,
      # cert_store: ssl_cert_store(ssl),
      # cert: options[:client_cert],
      # key: options[:client_key],
      # ca_file: ssl[:ca_file],
      # ca_path: ssl[:ca_path],
      # verify_depth: ssl[:verify_depth],
      # version: ssl[:version],
    )
  end
end