faraday 1.10.0 → 2.7.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +197 -3
 - data/LICENSE.md +1 -1
 - data/README.md +20 -17
 - data/Rakefile +3 -1
 - data/examples/client_spec.rb +41 -19
 - data/examples/client_test.rb +48 -22
 - data/lib/faraday/adapter/test.rb +61 -12
 - data/lib/faraday/adapter.rb +5 -9
 - data/lib/faraday/connection.rb +58 -145
 - data/lib/faraday/encoders/nested_params_encoder.rb +13 -6
 - data/lib/faraday/error.rb +16 -5
 - data/lib/faraday/logging/formatter.rb +27 -14
 - data/lib/faraday/middleware.rb +3 -1
 - data/lib/faraday/middleware_registry.rb +17 -63
 - data/lib/faraday/options/connection_options.rb +7 -6
 - data/lib/faraday/options/env.rb +85 -62
 - data/lib/faraday/options/proxy_options.rb +7 -3
 - data/lib/faraday/options/request_options.rb +7 -6
 - data/lib/faraday/options/ssl_options.rb +56 -45
 - data/lib/faraday/options.rb +4 -3
 - data/lib/faraday/rack_builder.rb +23 -20
 - data/lib/faraday/request/authorization.rb +33 -41
 - data/lib/faraday/request/instrumentation.rb +5 -1
 - data/lib/faraday/request/json.rb +10 -1
 - data/lib/faraday/request/url_encoded.rb +5 -1
 - data/lib/faraday/request.rb +15 -31
 - data/lib/faraday/response/json.rb +4 -4
 - data/lib/faraday/response/logger.rb +6 -0
 - data/lib/faraday/response/raise_error.rb +11 -1
 - data/lib/faraday/response.rb +9 -21
 - data/lib/faraday/utils/headers.rb +7 -2
 - data/lib/faraday/utils.rb +10 -5
 - data/lib/faraday/version.rb +1 -1
 - data/lib/faraday.rb +8 -44
 - data/spec/faraday/adapter/test_spec.rb +65 -0
 - data/spec/faraday/connection_spec.rb +163 -91
 - data/spec/faraday/error_spec.rb +31 -6
 - data/spec/faraday/middleware_registry_spec.rb +31 -0
 - data/spec/faraday/middleware_spec.rb +18 -0
 - data/spec/faraday/options/env_spec.rb +8 -2
 - data/spec/faraday/options/options_spec.rb +1 -1
 - data/spec/faraday/options/proxy_options_spec.rb +8 -0
 - data/spec/faraday/params_encoders/nested_spec.rb +8 -0
 - data/spec/faraday/rack_builder_spec.rb +26 -54
 - data/spec/faraday/request/authorization_spec.rb +50 -28
 - data/spec/faraday/request/instrumentation_spec.rb +5 -7
 - data/spec/faraday/request/json_spec.rb +24 -0
 - data/spec/faraday/request/url_encoded_spec.rb +12 -2
 - data/spec/faraday/request_spec.rb +5 -15
 - data/spec/faraday/response/json_spec.rb +4 -6
 - data/spec/faraday/response/logger_spec.rb +38 -0
 - data/spec/faraday/response/raise_error_spec.rb +19 -4
 - data/spec/faraday/response_spec.rb +3 -1
 - data/spec/faraday/utils/headers_spec.rb +22 -4
 - data/spec/faraday/utils_spec.rb +63 -1
 - data/spec/support/fake_safe_buffer.rb +1 -1
 - data/spec/support/helper_methods.rb +0 -37
 - data/spec/support/shared_examples/adapter.rb +2 -2
 - data/spec/support/shared_examples/request_method.rb +22 -21
 - metadata +14 -149
 - data/lib/faraday/adapter/typhoeus.rb +0 -15
 - data/lib/faraday/autoload.rb +0 -87
 - data/lib/faraday/dependency_loader.rb +0 -37
 - data/lib/faraday/request/basic_authentication.rb +0 -20
 - data/lib/faraday/request/token_authentication.rb +0 -20
 - data/spec/faraday/adapter/em_http_spec.rb +0 -49
 - data/spec/faraday/adapter/em_synchrony_spec.rb +0 -18
 - data/spec/faraday/adapter/excon_spec.rb +0 -49
 - data/spec/faraday/adapter/httpclient_spec.rb +0 -73
 - data/spec/faraday/adapter/net_http_spec.rb +0 -64
 - data/spec/faraday/adapter/patron_spec.rb +0 -18
 - data/spec/faraday/adapter/rack_spec.rb +0 -8
 - data/spec/faraday/adapter/typhoeus_spec.rb +0 -7
 - data/spec/faraday/composite_read_io_spec.rb +0 -80
 - data/spec/faraday/response/middleware_spec.rb +0 -68
 - data/spec/support/webmock_rack_app.rb +0 -68
 
| 
         @@ -1,41 +1,54 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require 'pp'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
       4 
5 
     | 
    
         
             
            module Faraday
         
     | 
| 
       5 
6 
     | 
    
         
             
              module Logging
         
     | 
| 
       6 
7 
     | 
    
         
             
                # Serves as an integration point to customize logging
         
     | 
| 
       7 
8 
     | 
    
         
             
                class Formatter
         
     | 
| 
       8 
9 
     | 
    
         
             
                  extend Forwardable
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
                  DEFAULT_OPTIONS = { headers: true, bodies: false,
         
     | 
| 
      
 11 
     | 
    
         
            +
                  DEFAULT_OPTIONS = { headers: true, bodies: false, errors: false,
         
     | 
| 
       11 
12 
     | 
    
         
             
                                      log_level: :info }.freeze
         
     | 
| 
       12 
13 
     | 
    
         | 
| 
       13 
14 
     | 
    
         
             
                  def initialize(logger:, options:)
         
     | 
| 
       14 
15 
     | 
    
         
             
                    @logger = logger
         
     | 
| 
       15 
     | 
    
         
            -
                    @filter = []
         
     | 
| 
       16 
16 
     | 
    
         
             
                    @options = DEFAULT_OPTIONS.merge(options)
         
     | 
| 
      
 17 
     | 
    
         
            +
                    unless %i[debug info warn error fatal].include?(@options[:log_level])
         
     | 
| 
      
 18 
     | 
    
         
            +
                      @options[:log_level] = :info
         
     | 
| 
      
 19 
     | 
    
         
            +
                    end
         
     | 
| 
      
 20 
     | 
    
         
            +
                    @filter = []
         
     | 
| 
       17 
21 
     | 
    
         
             
                  end
         
     | 
| 
       18 
22 
     | 
    
         | 
| 
       19 
23 
     | 
    
         
             
                  def_delegators :@logger, :debug, :info, :warn, :error, :fatal
         
     | 
| 
       20 
24 
     | 
    
         | 
| 
       21 
25 
     | 
    
         
             
                  def request(env)
         
     | 
| 
       22 
     | 
    
         
            -
                     
     | 
| 
      
 26 
     | 
    
         
            +
                    public_send(log_level, 'request') do
         
     | 
| 
       23 
27 
     | 
    
         
             
                      "#{env.method.upcase} #{apply_filters(env.url.to_s)}"
         
     | 
| 
       24 
28 
     | 
    
         
             
                    end
         
     | 
| 
       25 
     | 
    
         
            -
                    public_send(log_level, 'request', &request_log)
         
     | 
| 
       26 
29 
     | 
    
         | 
| 
       27 
30 
     | 
    
         
             
                    log_headers('request', env.request_headers) if log_headers?(:request)
         
     | 
| 
       28 
31 
     | 
    
         
             
                    log_body('request', env[:body]) if env[:body] && log_body?(:request)
         
     | 
| 
       29 
32 
     | 
    
         
             
                  end
         
     | 
| 
       30 
33 
     | 
    
         | 
| 
       31 
34 
     | 
    
         
             
                  def response(env)
         
     | 
| 
       32 
     | 
    
         
            -
                     
     | 
| 
       33 
     | 
    
         
            -
                    public_send(log_level, 'response', &status)
         
     | 
| 
      
 35 
     | 
    
         
            +
                    public_send(log_level, 'response') { "Status #{env.status}" }
         
     | 
| 
       34 
36 
     | 
    
         | 
| 
       35 
37 
     | 
    
         
             
                    log_headers('response', env.response_headers) if log_headers?(:response)
         
     | 
| 
       36 
38 
     | 
    
         
             
                    log_body('response', env[:body]) if env[:body] && log_body?(:response)
         
     | 
| 
       37 
39 
     | 
    
         
             
                  end
         
     | 
| 
       38 
40 
     | 
    
         | 
| 
      
 41 
     | 
    
         
            +
                  def exception(exc)
         
     | 
| 
      
 42 
     | 
    
         
            +
                    return unless log_errors?
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                    public_send(log_level, 'error') { exc.full_message }
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                    log_headers('error', exc.response_headers) if exc.respond_to?(:response_headers) && log_headers?(:error)
         
     | 
| 
      
 47 
     | 
    
         
            +
                    return unless exc.respond_to?(:response_body) && exc.response_body && log_body?(:error)
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                    log_body('error', exc.response_body)
         
     | 
| 
      
 50 
     | 
    
         
            +
                  end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
       39 
52 
     | 
    
         
             
                  def filter(filter_word, filter_replacement)
         
     | 
| 
       40 
53 
     | 
    
         
             
                    @filter.push([filter_word, filter_replacement])
         
     | 
| 
       41 
54 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -43,6 +56,8 @@ module Faraday 
     | 
|
| 
       43 
56 
     | 
    
         
             
                  private
         
     | 
| 
       44 
57 
     | 
    
         | 
| 
       45 
58 
     | 
    
         
             
                  def dump_headers(headers)
         
     | 
| 
      
 59 
     | 
    
         
            +
                    return if headers.nil?
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
       46 
61 
     | 
    
         
             
                    headers.map { |k, v| "#{k}: #{v.inspect}" }.join("\n")
         
     | 
| 
       47 
62 
     | 
    
         
             
                  end
         
     | 
| 
       48 
63 
     | 
    
         | 
| 
         @@ -76,6 +91,10 @@ module Faraday 
     | 
|
| 
       76 
91 
     | 
    
         
             
                    end
         
     | 
| 
       77 
92 
     | 
    
         
             
                  end
         
     | 
| 
       78 
93 
     | 
    
         | 
| 
      
 94 
     | 
    
         
            +
                  def log_errors?
         
     | 
| 
      
 95 
     | 
    
         
            +
                    @options[:errors]
         
     | 
| 
      
 96 
     | 
    
         
            +
                  end
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
       79 
98 
     | 
    
         
             
                  def apply_filters(output)
         
     | 
| 
       80 
99 
     | 
    
         
             
                    @filter.each do |pattern, replacement|
         
     | 
| 
       81 
100 
     | 
    
         
             
                      output = output.to_s.gsub(pattern, replacement)
         
     | 
| 
         @@ -84,21 +103,15 @@ module Faraday 
     | 
|
| 
       84 
103 
     | 
    
         
             
                  end
         
     | 
| 
       85 
104 
     | 
    
         | 
| 
       86 
105 
     | 
    
         
             
                  def log_level
         
     | 
| 
       87 
     | 
    
         
            -
                    unless %i[debug info warn error fatal].include?(@options[:log_level])
         
     | 
| 
       88 
     | 
    
         
            -
                      return :info
         
     | 
| 
       89 
     | 
    
         
            -
                    end
         
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
106 
     | 
    
         
             
                    @options[:log_level]
         
     | 
| 
       92 
107 
     | 
    
         
             
                  end
         
     | 
| 
       93 
108 
     | 
    
         | 
| 
       94 
109 
     | 
    
         
             
                  def log_headers(type, headers)
         
     | 
| 
       95 
     | 
    
         
            -
                     
     | 
| 
       96 
     | 
    
         
            -
                    public_send(log_level, type, &headers_log)
         
     | 
| 
      
 110 
     | 
    
         
            +
                    public_send(log_level, type) { apply_filters(dump_headers(headers)) }
         
     | 
| 
       97 
111 
     | 
    
         
             
                  end
         
     | 
| 
       98 
112 
     | 
    
         | 
| 
       99 
113 
     | 
    
         
             
                  def log_body(type, body)
         
     | 
| 
       100 
     | 
    
         
            -
                     
     | 
| 
       101 
     | 
    
         
            -
                    public_send(log_level, type, &body_log)
         
     | 
| 
      
 114 
     | 
    
         
            +
                    public_send(log_level, type) { apply_filters(dump_body(body)) }
         
     | 
| 
       102 
115 
     | 
    
         
             
                  end
         
     | 
| 
       103 
116 
     | 
    
         
             
                end
         
     | 
| 
       104 
117 
     | 
    
         
             
              end
         
     | 
    
        data/lib/faraday/middleware.rb
    CHANGED
    
    | 
         @@ -4,7 +4,6 @@ module Faraday 
     | 
|
| 
       4 
4 
     | 
    
         
             
              # Middleware is the basic base class of any Faraday middleware.
         
     | 
| 
       5 
5 
     | 
    
         
             
              class Middleware
         
     | 
| 
       6 
6 
     | 
    
         
             
                extend MiddlewareRegistry
         
     | 
| 
       7 
     | 
    
         
            -
                extend DependencyLoader
         
     | 
| 
       8 
7 
     | 
    
         | 
| 
       9 
8 
     | 
    
         
             
                attr_reader :app, :options
         
     | 
| 
       10 
9 
     | 
    
         | 
| 
         @@ -18,6 +17,9 @@ module Faraday 
     | 
|
| 
       18 
17 
     | 
    
         
             
                  app.call(env).on_complete do |environment|
         
     | 
| 
       19 
18 
     | 
    
         
             
                    on_complete(environment) if respond_to?(:on_complete)
         
     | 
| 
       20 
19 
     | 
    
         
             
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
                rescue StandardError => e
         
     | 
| 
      
 21 
     | 
    
         
            +
                  on_error(e) if respond_to?(:on_error)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  raise
         
     | 
| 
       21 
23 
     | 
    
         
             
                end
         
     | 
| 
       22 
24 
     | 
    
         | 
| 
       23 
25 
     | 
    
         
             
                def close
         
     | 
| 
         @@ -6,59 +6,26 @@ module Faraday 
     | 
|
| 
       6 
6 
     | 
    
         
             
              # Adds the ability for other modules to register and lookup
         
     | 
| 
       7 
7 
     | 
    
         
             
              # middleware classes.
         
     | 
| 
       8 
8 
     | 
    
         
             
              module MiddlewareRegistry
         
     | 
| 
      
 9 
     | 
    
         
            +
                def registered_middleware
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @registered_middleware ||= {}
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
       9 
13 
     | 
    
         
             
                # Register middleware class(es) on the current module.
         
     | 
| 
       10 
14 
     | 
    
         
             
                #
         
     | 
| 
       11 
     | 
    
         
            -
                # @param  
     | 
| 
       12 
     | 
    
         
            -
                # @param mapping [Hash{
         
     | 
| 
       13 
     | 
    
         
            -
                #          Symbol => Module,
         
     | 
| 
       14 
     | 
    
         
            -
                #          Symbol => Array<Module, Symbol, String>,
         
     | 
| 
       15 
     | 
    
         
            -
                #        }] Middleware mapping from a lookup symbol to a reference to the
         
     | 
| 
       16 
     | 
    
         
            -
                #        middleware.
         
     | 
| 
       17 
     | 
    
         
            -
                #        Classes can be expressed as:
         
     | 
| 
       18 
     | 
    
         
            -
                #          - a fully qualified constant
         
     | 
| 
       19 
     | 
    
         
            -
                #          - a Symbol
         
     | 
| 
       20 
     | 
    
         
            -
                #          - a Proc that will be lazily called to return the former
         
     | 
| 
       21 
     | 
    
         
            -
                #          - an array is given, its first element is the constant or symbol,
         
     | 
| 
       22 
     | 
    
         
            -
                #            and its second is a file to `require`.
         
     | 
| 
      
 15 
     | 
    
         
            +
                # @param mappings [Hash] Middleware mappings from a lookup symbol to a middleware class.
         
     | 
| 
       23 
16 
     | 
    
         
             
                # @return [void]
         
     | 
| 
       24 
17 
     | 
    
         
             
                #
         
     | 
| 
       25 
18 
     | 
    
         
             
                # @example Lookup by a constant
         
     | 
| 
       26 
19 
     | 
    
         
             
                #
         
     | 
| 
       27 
20 
     | 
    
         
             
                #   module Faraday
         
     | 
| 
       28 
     | 
    
         
            -
                #     class Whatever
         
     | 
| 
      
 21 
     | 
    
         
            +
                #     class Whatever < Middleware
         
     | 
| 
       29 
22 
     | 
    
         
             
                #       # Middleware looked up by :foo returns Faraday::Whatever::Foo.
         
     | 
| 
       30 
     | 
    
         
            -
                #       register_middleware 
     | 
| 
       31 
     | 
    
         
            -
                #     end
         
     | 
| 
       32 
     | 
    
         
            -
                #   end
         
     | 
| 
       33 
     | 
    
         
            -
                #
         
     | 
| 
       34 
     | 
    
         
            -
                # @example Lookup by a symbol
         
     | 
| 
       35 
     | 
    
         
            -
                #
         
     | 
| 
       36 
     | 
    
         
            -
                #   module Faraday
         
     | 
| 
       37 
     | 
    
         
            -
                #     class Whatever
         
     | 
| 
       38 
     | 
    
         
            -
                #       # Middleware looked up by :bar returns
         
     | 
| 
       39 
     | 
    
         
            -
                #       # Faraday::Whatever.const_get(:Bar)
         
     | 
| 
       40 
     | 
    
         
            -
                #       register_middleware bar: :Bar
         
     | 
| 
       41 
     | 
    
         
            -
                #     end
         
     | 
| 
       42 
     | 
    
         
            -
                #   end
         
     | 
| 
       43 
     | 
    
         
            -
                #
         
     | 
| 
       44 
     | 
    
         
            -
                # @example Lookup by a symbol and string in an array
         
     | 
| 
       45 
     | 
    
         
            -
                #
         
     | 
| 
       46 
     | 
    
         
            -
                #   module Faraday
         
     | 
| 
       47 
     | 
    
         
            -
                #     class Whatever
         
     | 
| 
       48 
     | 
    
         
            -
                #       # Middleware looked up by :baz requires 'baz' and returns
         
     | 
| 
       49 
     | 
    
         
            -
                #       # Faraday::Whatever.const_get(:Baz)
         
     | 
| 
       50 
     | 
    
         
            -
                #       register_middleware baz: [:Baz, 'baz']
         
     | 
| 
      
 23 
     | 
    
         
            +
                #       register_middleware(foo: Whatever)
         
     | 
| 
       51 
24 
     | 
    
         
             
                #     end
         
     | 
| 
       52 
25 
     | 
    
         
             
                #   end
         
     | 
| 
       53 
     | 
    
         
            -
                 
     | 
| 
       54 
     | 
    
         
            -
                def register_middleware(autoload_path = nil, mapping = nil)
         
     | 
| 
       55 
     | 
    
         
            -
                  if mapping.nil?
         
     | 
| 
       56 
     | 
    
         
            -
                    mapping = autoload_path
         
     | 
| 
       57 
     | 
    
         
            -
                    autoload_path = nil
         
     | 
| 
       58 
     | 
    
         
            -
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
                def register_middleware(**mappings)
         
     | 
| 
       59 
27 
     | 
    
         
             
                  middleware_mutex do
         
     | 
| 
       60 
     | 
    
         
            -
                     
     | 
| 
       61 
     | 
    
         
            -
                    (@registered_middleware ||= {}).update(mapping)
         
     | 
| 
      
 28 
     | 
    
         
            +
                    registered_middleware.update(mappings)
         
     | 
| 
       62 
29 
     | 
    
         
             
                  end
         
     | 
| 
       63 
30 
     | 
    
         
             
                end
         
     | 
| 
       64 
31 
     | 
    
         | 
| 
         @@ -66,7 +33,7 @@ module Faraday 
     | 
|
| 
       66 
33 
     | 
    
         
             
                #
         
     | 
| 
       67 
34 
     | 
    
         
             
                # @param key [Symbol] key for the registered middleware.
         
     | 
| 
       68 
35 
     | 
    
         
             
                def unregister_middleware(key)
         
     | 
| 
       69 
     | 
    
         
            -
                   
     | 
| 
      
 36 
     | 
    
         
            +
                  registered_middleware.delete(key)
         
     | 
| 
       70 
37 
     | 
    
         
             
                end
         
     | 
| 
       71 
38 
     | 
    
         | 
| 
       72 
39 
     | 
    
         
             
                # Lookup middleware class with a registered Symbol shortcut.
         
     | 
| 
         @@ -78,30 +45,27 @@ module Faraday 
     | 
|
| 
       78 
45 
     | 
    
         
             
                # @example
         
     | 
| 
       79 
46 
     | 
    
         
             
                #
         
     | 
| 
       80 
47 
     | 
    
         
             
                #   module Faraday
         
     | 
| 
       81 
     | 
    
         
            -
                #     class Whatever
         
     | 
| 
       82 
     | 
    
         
            -
                #       register_middleware 
     | 
| 
      
 48 
     | 
    
         
            +
                #     class Whatever < Middleware
         
     | 
| 
      
 49 
     | 
    
         
            +
                #       register_middleware(foo: Whatever)
         
     | 
| 
       83 
50 
     | 
    
         
             
                #     end
         
     | 
| 
       84 
51 
     | 
    
         
             
                #   end
         
     | 
| 
       85 
52 
     | 
    
         
             
                #
         
     | 
| 
       86 
     | 
    
         
            -
                #   Faraday:: 
     | 
| 
       87 
     | 
    
         
            -
                #   # => Faraday::Whatever 
     | 
| 
       88 
     | 
    
         
            -
                #
         
     | 
| 
      
 53 
     | 
    
         
            +
                #   Faraday::Middleware.lookup_middleware(:foo)
         
     | 
| 
      
 54 
     | 
    
         
            +
                #   # => Faraday::Whatever
         
     | 
| 
       89 
55 
     | 
    
         
             
                def lookup_middleware(key)
         
     | 
| 
       90 
56 
     | 
    
         
             
                  load_middleware(key) ||
         
     | 
| 
       91 
57 
     | 
    
         
             
                    raise(Faraday::Error, "#{key.inspect} is not registered on #{self}")
         
     | 
| 
       92 
58 
     | 
    
         
             
                end
         
     | 
| 
       93 
59 
     | 
    
         | 
| 
      
 60 
     | 
    
         
            +
                private
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
       94 
62 
     | 
    
         
             
                def middleware_mutex(&block)
         
     | 
| 
       95 
63 
     | 
    
         
             
                  @middleware_mutex ||= Monitor.new
         
     | 
| 
       96 
64 
     | 
    
         
             
                  @middleware_mutex.synchronize(&block)
         
     | 
| 
       97 
65 
     | 
    
         
             
                end
         
     | 
| 
       98 
66 
     | 
    
         | 
| 
       99 
     | 
    
         
            -
                def fetch_middleware(key)
         
     | 
| 
       100 
     | 
    
         
            -
                  defined?(@registered_middleware) && @registered_middleware[key]
         
     | 
| 
       101 
     | 
    
         
            -
                end
         
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
67 
     | 
    
         
             
                def load_middleware(key)
         
     | 
| 
       104 
     | 
    
         
            -
                  value =  
     | 
| 
      
 68 
     | 
    
         
            +
                  value = registered_middleware[key]
         
     | 
| 
       105 
69 
     | 
    
         
             
                  case value
         
     | 
| 
       106 
70 
     | 
    
         
             
                  when Module
         
     | 
| 
       107 
71 
     | 
    
         
             
                    value
         
     | 
| 
         @@ -113,16 +77,6 @@ module Faraday 
     | 
|
| 
       113 
77 
     | 
    
         
             
                    middleware_mutex do
         
     | 
| 
       114 
78 
     | 
    
         
             
                      @registered_middleware[key] = value.call
         
     | 
| 
       115 
79 
     | 
    
         
             
                    end
         
     | 
| 
       116 
     | 
    
         
            -
                  when Array
         
     | 
| 
       117 
     | 
    
         
            -
                    middleware_mutex do
         
     | 
| 
       118 
     | 
    
         
            -
                      const, path = value
         
     | 
| 
       119 
     | 
    
         
            -
                      if (root = @middleware_autoload_path)
         
     | 
| 
       120 
     | 
    
         
            -
                        path = "#{root}/#{path}"
         
     | 
| 
       121 
     | 
    
         
            -
                      end
         
     | 
| 
       122 
     | 
    
         
            -
                      require(path)
         
     | 
| 
       123 
     | 
    
         
            -
                      @registered_middleware[key] = const
         
     | 
| 
       124 
     | 
    
         
            -
                    end
         
     | 
| 
       125 
     | 
    
         
            -
                    load_middleware(key)
         
     | 
| 
       126 
80 
     | 
    
         
             
                  end
         
     | 
| 
       127 
81 
     | 
    
         
             
                end
         
     | 
| 
       128 
82 
     | 
    
         
             
              end
         
     | 
| 
         @@ -1,12 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module Faraday
         
     | 
| 
       4 
     | 
    
         
            -
              #  
     | 
| 
       5 
     | 
    
         
            -
              #  
     | 
| 
       6 
     | 
    
         
            -
               
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
              # @!parse
         
     | 
| 
      
 5 
     | 
    
         
            +
              #   # ConnectionOptions contains the configurable properties for a Faraday
         
     | 
| 
      
 6 
     | 
    
         
            +
              #   # connection object.
         
     | 
| 
      
 7 
     | 
    
         
            +
              #   class ConnectionOptions < Options; end
         
     | 
| 
      
 8 
     | 
    
         
            +
              ConnectionOptions = Options.new(:request, :proxy, :ssl, :builder, :url,
         
     | 
| 
      
 9 
     | 
    
         
            +
                                              :parallel_manager, :params, :headers,
         
     | 
| 
      
 10 
     | 
    
         
            +
                                              :builder_class) do
         
     | 
| 
       10 
11 
     | 
    
         
             
                options request: RequestOptions, ssl: SSLOptions
         
     | 
| 
       11 
12 
     | 
    
         | 
| 
       12 
13 
     | 
    
         
             
                memoized(:request) { self.class.options_for(:request).new }
         
     | 
    
        data/lib/faraday/options/env.rb
    CHANGED
    
    | 
         @@ -1,65 +1,70 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module Faraday
         
     | 
| 
       4 
     | 
    
         
            -
              # @! 
     | 
| 
       5 
     | 
    
         
            -
              #    
     | 
| 
       6 
     | 
    
         
            -
              #
         
     | 
| 
       7 
     | 
    
         
            -
              # 
     | 
| 
       8 
     | 
    
         
            -
              #    
     | 
| 
       9 
     | 
    
         
            -
              #    
     | 
| 
       10 
     | 
    
         
            -
              #
         
     | 
| 
       11 
     | 
    
         
            -
              # 
     | 
| 
       12 
     | 
    
         
            -
              #    
     | 
| 
       13 
     | 
    
         
            -
              #
         
     | 
| 
       14 
     | 
    
         
            -
              # 
     | 
| 
       15 
     | 
    
         
            -
              #    
     | 
| 
       16 
     | 
    
         
            -
              #    
     | 
| 
       17 
     | 
    
         
            -
              #
         
     | 
| 
       18 
     | 
    
         
            -
              #    
     | 
| 
       19 
     | 
    
         
            -
              #   - `: 
     | 
| 
       20 
     | 
    
         
            -
              #    
     | 
| 
       21 
     | 
    
         
            -
              #   - `: 
     | 
| 
       22 
     | 
    
         
            -
              # 
     | 
| 
       23 
     | 
    
         
            -
              # 
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
              # @!parse
         
     | 
| 
      
 5 
     | 
    
         
            +
              #   # @!attribute method
         
     | 
| 
      
 6 
     | 
    
         
            +
              #   #   @return [Symbol] HTTP method (`:get`, `:post`)
         
     | 
| 
      
 7 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 8 
     | 
    
         
            +
              #   # @!attribute body
         
     | 
| 
      
 9 
     | 
    
         
            +
              #   #   @return [String] The request body that will eventually be converted to a
         
     | 
| 
      
 10 
     | 
    
         
            +
              #   #   string.
         
     | 
| 
      
 11 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 12 
     | 
    
         
            +
              #   # @!attribute url
         
     | 
| 
      
 13 
     | 
    
         
            +
              #   #   @return [URI] URI instance for the current request.
         
     | 
| 
      
 14 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 15 
     | 
    
         
            +
              #   # @!attribute request
         
     | 
| 
      
 16 
     | 
    
         
            +
              #   #   @return [Hash] options for configuring the request.
         
     | 
| 
      
 17 
     | 
    
         
            +
              #   #   Options for configuring the request.
         
     | 
| 
      
 18 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 19 
     | 
    
         
            +
              #   #   - `:timeout`       - time limit for the entire request (Integer in
         
     | 
| 
      
 20 
     | 
    
         
            +
              #   #                        seconds)
         
     | 
| 
      
 21 
     | 
    
         
            +
              #   #   - `:open_timeout`  - time limit for just the connection phase (e.g.
         
     | 
| 
      
 22 
     | 
    
         
            +
              #   #                        handshake) (Integer in seconds)
         
     | 
| 
      
 23 
     | 
    
         
            +
              #   #   - `:read_timeout`  - time limit for the first response byte received from
         
     | 
| 
      
 24 
     | 
    
         
            +
              #   #                        the server (Integer in seconds)
         
     | 
| 
      
 25 
     | 
    
         
            +
              #   #   - `:write_timeout` - time limit for the client to send the request to the
         
     | 
| 
      
 26 
     | 
    
         
            +
              #   #                        server (Integer in seconds)
         
     | 
| 
      
 27 
     | 
    
         
            +
              #   #   - `:on_data`       - Proc for streaming
         
     | 
| 
      
 28 
     | 
    
         
            +
              #   #   - `:proxy`         - Hash of proxy options
         
     | 
| 
      
 29 
     | 
    
         
            +
              #   #       - `:uri`         - Proxy server URI
         
     | 
| 
      
 30 
     | 
    
         
            +
              #   #       - `:user`        - Proxy server username
         
     | 
| 
      
 31 
     | 
    
         
            +
              #   #       - `:password`    - Proxy server password
         
     | 
| 
      
 32 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 33 
     | 
    
         
            +
              #   # @!attribute request_headers
         
     | 
| 
      
 34 
     | 
    
         
            +
              #   #   @return [Hash] HTTP Headers to be sent to the server.
         
     | 
| 
      
 35 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 36 
     | 
    
         
            +
              #   # @!attribute ssl
         
     | 
| 
      
 37 
     | 
    
         
            +
              #   #   @return [Hash] options for configuring SSL requests
         
     | 
| 
      
 38 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 39 
     | 
    
         
            +
              #   # @!attribute parallel_manager
         
     | 
| 
      
 40 
     | 
    
         
            +
              #   #   @return [Object] sent if the connection is in parallel mode
         
     | 
| 
      
 41 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 42 
     | 
    
         
            +
              #   # @!attribute params
         
     | 
| 
      
 43 
     | 
    
         
            +
              #   #   @return [Hash]
         
     | 
| 
      
 44 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 45 
     | 
    
         
            +
              #   # @!attribute response
         
     | 
| 
      
 46 
     | 
    
         
            +
              #   #   @return [Response]
         
     | 
| 
      
 47 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 48 
     | 
    
         
            +
              #   # @!attribute response_headers
         
     | 
| 
      
 49 
     | 
    
         
            +
              #   #   @return [Hash] HTTP headers from the server
         
     | 
| 
      
 50 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 51 
     | 
    
         
            +
              #   # @!attribute status
         
     | 
| 
      
 52 
     | 
    
         
            +
              #   #   @return [Integer] HTTP response status code
         
     | 
| 
      
 53 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 54 
     | 
    
         
            +
              #   # @!attribute reason_phrase
         
     | 
| 
      
 55 
     | 
    
         
            +
              #   #   @return [String]
         
     | 
| 
      
 56 
     | 
    
         
            +
              #   class Env < Options; end
         
     | 
| 
      
 57 
     | 
    
         
            +
              Env = Options.new(:method, :request_body, :url, :request,
         
     | 
| 
      
 58 
     | 
    
         
            +
                                :request_headers, :ssl, :parallel_manager, :params,
         
     | 
| 
      
 59 
     | 
    
         
            +
                                :response, :response_headers, :status,
         
     | 
| 
      
 60 
     | 
    
         
            +
                                :reason_phrase, :response_body) do
         
     | 
| 
      
 61 
     | 
    
         
            +
                const_set(:ContentLength, 'Content-Length')
         
     | 
| 
      
 62 
     | 
    
         
            +
                const_set(:StatusesWithoutBody, Set.new([204, 304]))
         
     | 
| 
      
 63 
     | 
    
         
            +
                const_set(:SuccessfulStatuses, (200..299).freeze)
         
     | 
| 
       59 
64 
     | 
    
         | 
| 
       60 
65 
     | 
    
         
             
                # A Set of HTTP verbs that typically send a body.  If no body is set for
         
     | 
| 
       61 
66 
     | 
    
         
             
                # these requests, the Content-Length header is set to 0.
         
     | 
| 
       62 
     | 
    
         
            -
                MethodsWithBodies  
     | 
| 
      
 67 
     | 
    
         
            +
                const_set(:MethodsWithBodies, Set.new(Faraday::METHODS_WITH_BODY.map(&:to_sym)))
         
     | 
| 
       63 
68 
     | 
    
         | 
| 
       64 
69 
     | 
    
         
             
                options request: RequestOptions,
         
     | 
| 
       65 
70 
     | 
    
         
             
                        request_headers: Utils::Headers, response_headers: Utils::Headers
         
     | 
| 
         @@ -120,25 +125,25 @@ module Faraday 
     | 
|
| 
       120 
125 
     | 
    
         | 
| 
       121 
126 
     | 
    
         
             
                # @return [Boolean] true if status is in the set of {SuccessfulStatuses}.
         
     | 
| 
       122 
127 
     | 
    
         
             
                def success?
         
     | 
| 
       123 
     | 
    
         
            -
                  SuccessfulStatuses.include?(status)
         
     | 
| 
      
 128 
     | 
    
         
            +
                  Env::SuccessfulStatuses.include?(status)
         
     | 
| 
       124 
129 
     | 
    
         
             
                end
         
     | 
| 
       125 
130 
     | 
    
         | 
| 
       126 
131 
     | 
    
         
             
                # @return [Boolean] true if there's no body yet, and the method is in the
         
     | 
| 
       127 
     | 
    
         
            -
                # set of {MethodsWithBodies}.
         
     | 
| 
      
 132 
     | 
    
         
            +
                # set of {Env::MethodsWithBodies}.
         
     | 
| 
       128 
133 
     | 
    
         
             
                def needs_body?
         
     | 
| 
       129 
     | 
    
         
            -
                  !body && MethodsWithBodies.include?(method)
         
     | 
| 
      
 134 
     | 
    
         
            +
                  !body && Env::MethodsWithBodies.include?(method)
         
     | 
| 
       130 
135 
     | 
    
         
             
                end
         
     | 
| 
       131 
136 
     | 
    
         | 
| 
       132 
137 
     | 
    
         
             
                # Sets content length to zero and the body to the empty string.
         
     | 
| 
       133 
138 
     | 
    
         
             
                def clear_body
         
     | 
| 
       134 
     | 
    
         
            -
                  request_headers[ContentLength] = '0'
         
     | 
| 
      
 139 
     | 
    
         
            +
                  request_headers[Env::ContentLength] = '0'
         
     | 
| 
       135 
140 
     | 
    
         
             
                  self.body = +''
         
     | 
| 
       136 
141 
     | 
    
         
             
                end
         
     | 
| 
       137 
142 
     | 
    
         | 
| 
       138 
143 
     | 
    
         
             
                # @return [Boolean] true if the status isn't in the set of
         
     | 
| 
       139 
     | 
    
         
            -
                # {StatusesWithoutBody}.
         
     | 
| 
      
 144 
     | 
    
         
            +
                # {Env::StatusesWithoutBody}.
         
     | 
| 
       140 
145 
     | 
    
         
             
                def parse_body?
         
     | 
| 
       141 
     | 
    
         
            -
                  !StatusesWithoutBody.include?(status)
         
     | 
| 
      
 146 
     | 
    
         
            +
                  !Env::StatusesWithoutBody.include?(status)
         
     | 
| 
       142 
147 
     | 
    
         
             
                end
         
     | 
| 
       143 
148 
     | 
    
         | 
| 
       144 
149 
     | 
    
         
             
                # @return [Boolean] true if there is a parallel_manager
         
     | 
| 
         @@ -157,6 +162,24 @@ module Faraday 
     | 
|
| 
       157 
162 
     | 
    
         
             
                  %(#<#{self.class}#{attrs.join(' ')}>)
         
     | 
| 
       158 
163 
     | 
    
         
             
                end
         
     | 
| 
       159 
164 
     | 
    
         | 
| 
      
 165 
     | 
    
         
            +
                def stream_response?
         
     | 
| 
      
 166 
     | 
    
         
            +
                  request.stream_response?
         
     | 
| 
      
 167 
     | 
    
         
            +
                end
         
     | 
| 
      
 168 
     | 
    
         
            +
             
     | 
| 
      
 169 
     | 
    
         
            +
                def stream_response(&block)
         
     | 
| 
      
 170 
     | 
    
         
            +
                  size = 0
         
     | 
| 
      
 171 
     | 
    
         
            +
                  yielded = false
         
     | 
| 
      
 172 
     | 
    
         
            +
                  block_result = block.call do |chunk| # rubocop:disable Performance/RedundantBlockCall
         
     | 
| 
      
 173 
     | 
    
         
            +
                    if chunk.bytesize.positive? || size.positive?
         
     | 
| 
      
 174 
     | 
    
         
            +
                      yielded = true
         
     | 
| 
      
 175 
     | 
    
         
            +
                      size += chunk.bytesize
         
     | 
| 
      
 176 
     | 
    
         
            +
                      request.on_data.call(chunk, size, self)
         
     | 
| 
      
 177 
     | 
    
         
            +
                    end
         
     | 
| 
      
 178 
     | 
    
         
            +
                  end
         
     | 
| 
      
 179 
     | 
    
         
            +
                  request.on_data.call(+'', 0, self) unless yielded
         
     | 
| 
      
 180 
     | 
    
         
            +
                  block_result
         
     | 
| 
      
 181 
     | 
    
         
            +
                end
         
     | 
| 
      
 182 
     | 
    
         
            +
             
     | 
| 
       160 
183 
     | 
    
         
             
                # @private
         
     | 
| 
       161 
184 
     | 
    
         
             
                def custom_members
         
     | 
| 
       162 
185 
     | 
    
         
             
                  @custom_members ||= {}
         
     | 
| 
         @@ -1,15 +1,19 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module Faraday
         
     | 
| 
       4 
     | 
    
         
            -
              #  
     | 
| 
       5 
     | 
    
         
            -
              #  
     | 
| 
       6 
     | 
    
         
            -
               
     | 
| 
      
 4 
     | 
    
         
            +
              # @!parse
         
     | 
| 
      
 5 
     | 
    
         
            +
              #   # ProxyOptions contains the configurable properties for the proxy
         
     | 
| 
      
 6 
     | 
    
         
            +
              #   # configuration used when making an HTTP request.
         
     | 
| 
      
 7 
     | 
    
         
            +
              #   class ProxyOptions < Options; end
         
     | 
| 
      
 8 
     | 
    
         
            +
              ProxyOptions = Options.new(:uri, :user, :password) do
         
     | 
| 
       7 
9 
     | 
    
         
             
                extend Forwardable
         
     | 
| 
       8 
10 
     | 
    
         
             
                def_delegators :uri, :scheme, :scheme=, :host, :host=, :port, :port=,
         
     | 
| 
       9 
11 
     | 
    
         
             
                               :path, :path=
         
     | 
| 
       10 
12 
     | 
    
         | 
| 
       11 
13 
     | 
    
         
             
                def self.from(value)
         
     | 
| 
       12 
14 
     | 
    
         
             
                  case value
         
     | 
| 
      
 15 
     | 
    
         
            +
                  when ''
         
     | 
| 
      
 16 
     | 
    
         
            +
                    value = nil
         
     | 
| 
       13 
17 
     | 
    
         
             
                  when String
         
     | 
| 
       14 
18 
     | 
    
         
             
                    # URIs without a scheme should default to http (like 'example:123').
         
     | 
| 
       15 
19 
     | 
    
         
             
                    # This fixes #1282 and prevents a silent failure in some adapters.
         
     | 
| 
         @@ -1,12 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module Faraday
         
     | 
| 
       4 
     | 
    
         
            -
              #  
     | 
| 
       5 
     | 
    
         
            -
               
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
              # @!parse
         
     | 
| 
      
 5 
     | 
    
         
            +
              #   # RequestOptions contains the configurable properties for a Faraday request.
         
     | 
| 
      
 6 
     | 
    
         
            +
              #   class RequestOptions < Options; end
         
     | 
| 
      
 7 
     | 
    
         
            +
              RequestOptions = Options.new(:params_encoder, :proxy, :bind,
         
     | 
| 
      
 8 
     | 
    
         
            +
                                           :timeout, :open_timeout, :read_timeout,
         
     | 
| 
      
 9 
     | 
    
         
            +
                                           :write_timeout, :boundary, :oauth,
         
     | 
| 
      
 10 
     | 
    
         
            +
                                           :context, :on_data) do
         
     | 
| 
       10 
11 
     | 
    
         
             
                def []=(key, value)
         
     | 
| 
       11 
12 
     | 
    
         
             
                  if key && key.to_sym == :proxy
         
     | 
| 
       12 
13 
     | 
    
         
             
                    super(key, value ? ProxyOptions.from(value) : nil)
         
     | 
| 
         @@ -1,51 +1,57 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module Faraday
         
     | 
| 
       4 
     | 
    
         
            -
              #  
     | 
| 
       5 
     | 
    
         
            -
              #
         
     | 
| 
       6 
     | 
    
         
            -
              # 
     | 
| 
       7 
     | 
    
         
            -
              #    
     | 
| 
       8 
     | 
    
         
            -
              #
         
     | 
| 
       9 
     | 
    
         
            -
              # 
     | 
| 
       10 
     | 
    
         
            -
              #    
     | 
| 
       11 
     | 
    
         
            -
              #
         
     | 
| 
       12 
     | 
    
         
            -
              #  
     | 
| 
       13 
     | 
    
         
            -
              #    
     | 
| 
       14 
     | 
    
         
            -
              #
         
     | 
| 
       15 
     | 
    
         
            -
              #  
     | 
| 
       16 
     | 
    
         
            -
              #    
     | 
| 
       17 
     | 
    
         
            -
              #
         
     | 
| 
       18 
     | 
    
         
            -
              #  
     | 
| 
       19 
     | 
    
         
            -
              #    
     | 
| 
       20 
     | 
    
         
            -
              #
         
     | 
| 
       21 
     | 
    
         
            -
              #  
     | 
| 
       22 
     | 
    
         
            -
              #    
     | 
| 
       23 
     | 
    
         
            -
              #
         
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
              # @!parse
         
     | 
| 
      
 5 
     | 
    
         
            +
              #   # SSL-related options.
         
     | 
| 
      
 6 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 7 
     | 
    
         
            +
              #   # @!attribute verify
         
     | 
| 
      
 8 
     | 
    
         
            +
              #   #   @return [Boolean] whether to verify SSL certificates or not
         
     | 
| 
      
 9 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 10 
     | 
    
         
            +
              #   # @!attribute verify_hostname
         
     | 
| 
      
 11 
     | 
    
         
            +
              #   #   @return [Boolean] whether to enable hostname verification on server certificates
         
     | 
| 
      
 12 
     | 
    
         
            +
              #   #           during the handshake or not (see https://github.com/ruby/openssl/pull/60)
         
     | 
| 
      
 13 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 14 
     | 
    
         
            +
              #   # @!attribute ca_file
         
     | 
| 
      
 15 
     | 
    
         
            +
              #   #   @return [String] CA file
         
     | 
| 
      
 16 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 17 
     | 
    
         
            +
              #   # @!attribute ca_path
         
     | 
| 
      
 18 
     | 
    
         
            +
              #   #   @return [String] CA path
         
     | 
| 
      
 19 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 20 
     | 
    
         
            +
              #   # @!attribute verify_mode
         
     | 
| 
      
 21 
     | 
    
         
            +
              #   #   @return [Integer] Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
         
     | 
| 
      
 22 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 23 
     | 
    
         
            +
              #   # @!attribute cert_store
         
     | 
| 
      
 24 
     | 
    
         
            +
              #   #   @return [OpenSSL::X509::Store] certificate store
         
     | 
| 
      
 25 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 26 
     | 
    
         
            +
              #   # @!attribute client_cert
         
     | 
| 
      
 27 
     | 
    
         
            +
              #   #   @return [String, OpenSSL::X509::Certificate] client certificate
         
     | 
| 
      
 28 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 29 
     | 
    
         
            +
              #   # @!attribute client_key
         
     | 
| 
      
 30 
     | 
    
         
            +
              #   #   @return [String, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA] client key
         
     | 
| 
      
 31 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 32 
     | 
    
         
            +
              #   # @!attribute certificate
         
     | 
| 
      
 33 
     | 
    
         
            +
              #   #   @return [OpenSSL::X509::Certificate] certificate (Excon only)
         
     | 
| 
      
 34 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 35 
     | 
    
         
            +
              #   # @!attribute private_key
         
     | 
| 
      
 36 
     | 
    
         
            +
              #   #   @return [OpenSSL::PKey::RSA, OpenSSL::PKey::DSA] private key (Excon only)
         
     | 
| 
      
 37 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 38 
     | 
    
         
            +
              #   # @!attribute verify_depth
         
     | 
| 
      
 39 
     | 
    
         
            +
              #   #   @return [Integer] maximum depth for the certificate chain verification
         
     | 
| 
      
 40 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 41 
     | 
    
         
            +
              #   # @!attribute version
         
     | 
| 
      
 42 
     | 
    
         
            +
              #   #   @return [String, Symbol] SSL version (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html#method-i-ssl_version-3D)
         
     | 
| 
      
 43 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 44 
     | 
    
         
            +
              #   # @!attribute min_version
         
     | 
| 
      
 45 
     | 
    
         
            +
              #   #   @return [String, Symbol] minimum SSL version (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html#method-i-min_version-3D)
         
     | 
| 
      
 46 
     | 
    
         
            +
              #   #
         
     | 
| 
      
 47 
     | 
    
         
            +
              #   # @!attribute max_version
         
     | 
| 
      
 48 
     | 
    
         
            +
              #   #   @return [String, Symbol] maximum SSL version (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html#method-i-max_version-3D)
         
     | 
| 
      
 49 
     | 
    
         
            +
              #   class SSLOptions < Options; end
         
     | 
| 
      
 50 
     | 
    
         
            +
              SSLOptions = Options.new(:verify, :verify_hostname,
         
     | 
| 
      
 51 
     | 
    
         
            +
                                       :ca_file, :ca_path, :verify_mode,
         
     | 
| 
      
 52 
     | 
    
         
            +
                                       :cert_store, :client_cert, :client_key,
         
     | 
| 
      
 53 
     | 
    
         
            +
                                       :certificate, :private_key, :verify_depth,
         
     | 
| 
      
 54 
     | 
    
         
            +
                                       :version, :min_version, :max_version) do
         
     | 
| 
       49 
55 
     | 
    
         
             
                # @return [Boolean] true if should verify
         
     | 
| 
       50 
56 
     | 
    
         
             
                def verify?
         
     | 
| 
       51 
57 
     | 
    
         
             
                  verify != false
         
     | 
| 
         @@ -55,5 +61,10 @@ module Faraday 
     | 
|
| 
       55 
61 
     | 
    
         
             
                def disable?
         
     | 
| 
       56 
62 
     | 
    
         
             
                  !verify?
         
     | 
| 
       57 
63 
     | 
    
         
             
                end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                # @return [Boolean] true if should verify_hostname
         
     | 
| 
      
 66 
     | 
    
         
            +
                def verify_hostname?
         
     | 
| 
      
 67 
     | 
    
         
            +
                  verify_hostname != false
         
     | 
| 
      
 68 
     | 
    
         
            +
                end
         
     | 
| 
       58 
69 
     | 
    
         
             
              end
         
     | 
| 
       59 
70 
     | 
    
         
             
            end
         
     | 
    
        data/lib/faraday/options.rb
    CHANGED
    
    | 
         @@ -104,7 +104,7 @@ module Faraday 
     | 
|
| 
       104 
104 
     | 
    
         | 
| 
       105 
105 
     | 
    
         
             
                # Public
         
     | 
| 
       106 
106 
     | 
    
         
             
                def each_key(&block)
         
     | 
| 
       107 
     | 
    
         
            -
                  return to_enum(:each_key) unless  
     | 
| 
      
 107 
     | 
    
         
            +
                  return to_enum(:each_key) unless block
         
     | 
| 
       108 
108 
     | 
    
         | 
| 
       109 
109 
     | 
    
         
             
                  keys.each(&block)
         
     | 
| 
       110 
110 
     | 
    
         
             
                end
         
     | 
| 
         @@ -118,7 +118,7 @@ module Faraday 
     | 
|
| 
       118 
118 
     | 
    
         | 
| 
       119 
119 
     | 
    
         
             
                # Public
         
     | 
| 
       120 
120 
     | 
    
         
             
                def each_value(&block)
         
     | 
| 
       121 
     | 
    
         
            -
                  return to_enum(:each_value) unless  
     | 
| 
      
 121 
     | 
    
         
            +
                  return to_enum(:each_value) unless block
         
     | 
| 
       122 
122 
     | 
    
         | 
| 
       123 
123 
     | 
    
         
             
                  values.each(&block)
         
     | 
| 
       124 
124 
     | 
    
         
             
                end
         
     | 
| 
         @@ -168,12 +168,13 @@ module Faraday 
     | 
|
| 
       168 
168 
     | 
    
         
             
                end
         
     | 
| 
       169 
169 
     | 
    
         | 
| 
       170 
170 
     | 
    
         
             
                def self.memoized(key, &block)
         
     | 
| 
       171 
     | 
    
         
            -
                  unless  
     | 
| 
      
 171 
     | 
    
         
            +
                  unless block
         
     | 
| 
       172 
172 
     | 
    
         
             
                    raise ArgumentError, '#memoized must be called with a block'
         
     | 
| 
       173 
173 
     | 
    
         
             
                  end
         
     | 
| 
       174 
174 
     | 
    
         | 
| 
       175 
175 
     | 
    
         
             
                  memoized_attributes[key.to_sym] = block
         
     | 
| 
       176 
176 
     | 
    
         
             
                  class_eval <<-RUBY, __FILE__, __LINE__ + 1
         
     | 
| 
      
 177 
     | 
    
         
            +
                    remove_method(key) if method_defined?(key, false)
         
     | 
| 
       177 
178 
     | 
    
         
             
                    def #{key}() self[:#{key}]; end
         
     | 
| 
       178 
179 
     | 
    
         
             
                  RUBY
         
     | 
| 
       179 
180 
     | 
    
         
             
                end
         
     |