]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/aviator/feature/faraday/adapter.rb
add aimonb/aviator to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / aviator / feature / faraday / adapter.rb
1 module Faraday
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
6
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']
18
19     # Public: This module marks an Adapter as supporting parallel requests.
20     module Parallelism
21       attr_writer :supports_parallel
22       def supports_parallel?() @supports_parallel end
23
24       def inherited(subclass)
25         super
26         subclass.supports_parallel = self.supports_parallel?
27       end
28     end
29
30     extend Parallelism
31     self.supports_parallel = false
32
33     def call(env)
34       env.clear_body if env.needs_body?
35     end
36
37     def save_response(env, status, body, headers = nil)
38       env.status = status
39       env.body = body
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?
43       end
44     end
45   end
46 end