2 # Public: This is a base class for all Faraday adapters. Adapters are
3 # responsible for fulfilling a Faraday request.
4 class Adapter < Middleware
5 CONTENT_LENGTH = 'Content-Length'.freeze
7 register_middleware File.expand_path('../adapter', __FILE__),
8 :test => [:Test, 'test'],
9 :net_http => [:NetHttp, 'net_http'],
10 :net_http_persistent => [:NetHttpPersistent, 'net_http_persistent'],
11 :typhoeus => [:Typhoeus, 'typhoeus'],
12 :patron => [:Patron, 'patron'],
13 :em_synchrony => [:EMSynchrony, 'em_synchrony'],
14 :em_http => [:EMHttp, 'em_http'],
15 :excon => [:Excon, 'excon'],
16 :rack => [:Rack, 'rack'],
17 :httpclient => [:HTTPClient, 'httpclient']
19 # Public: This module marks an Adapter as supporting parallel requests.
21 attr_writer :supports_parallel
22 def supports_parallel?() @supports_parallel end
24 def inherited(subclass)
26 subclass.supports_parallel = self.supports_parallel?
31 self.supports_parallel = false
34 env.clear_body if env.needs_body?
37 def save_response(env, status, body, headers = nil)
40 env.response_headers = Utils::Headers.new.tap do |response_headers|
41 response_headers.update headers unless headers.nil?
42 yield(response_headers) if block_given?