faraday 0.16.2 → 0.17.0

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +1 -1
  3. data/README.md +347 -18
  4. data/lib/faraday.rb +175 -93
  5. data/lib/faraday/adapter.rb +22 -36
  6. data/lib/faraday/adapter/em_http.rb +99 -142
  7. data/lib/faraday/adapter/em_http_ssl_patch.rb +17 -23
  8. data/lib/faraday/adapter/em_synchrony.rb +60 -104
  9. data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +15 -18
  10. data/lib/faraday/adapter/excon.rb +55 -100
  11. data/lib/faraday/adapter/httpclient.rb +39 -61
  12. data/lib/faraday/adapter/net_http.rb +51 -104
  13. data/lib/faraday/adapter/net_http_persistent.rb +27 -48
  14. data/lib/faraday/adapter/patron.rb +35 -54
  15. data/lib/faraday/adapter/rack.rb +12 -28
  16. data/lib/faraday/adapter/test.rb +53 -86
  17. data/lib/faraday/adapter/typhoeus.rb +1 -4
  18. data/lib/faraday/autoload.rb +36 -47
  19. data/lib/faraday/connection.rb +179 -321
  20. data/lib/faraday/error.rb +32 -80
  21. data/lib/faraday/middleware.rb +28 -4
  22. data/lib/faraday/options.rb +186 -35
  23. data/lib/faraday/parameters.rb +197 -4
  24. data/lib/faraday/rack_builder.rb +56 -67
  25. data/lib/faraday/request.rb +36 -68
  26. data/lib/faraday/request/authorization.rb +30 -42
  27. data/lib/faraday/request/basic_authentication.rb +7 -14
  28. data/lib/faraday/request/instrumentation.rb +27 -45
  29. data/lib/faraday/request/multipart.rb +48 -79
  30. data/lib/faraday/request/retry.rb +170 -197
  31. data/lib/faraday/request/token_authentication.rb +10 -15
  32. data/lib/faraday/request/url_encoded.rb +23 -41
  33. data/lib/faraday/response.rb +16 -23
  34. data/lib/faraday/response/logger.rb +69 -22
  35. data/lib/faraday/response/raise_error.rb +14 -36
  36. data/lib/faraday/upload_io.rb +67 -0
  37. data/lib/faraday/utils.rb +245 -28
  38. metadata +5 -22
  39. data/lib/faraday/adapter_registry.rb +0 -28
  40. data/lib/faraday/dependency_loader.rb +0 -37
  41. data/lib/faraday/deprecated_class.rb +0 -28
  42. data/lib/faraday/encoders/flat_params_encoder.rb +0 -94
  43. data/lib/faraday/encoders/nested_params_encoder.rb +0 -171
  44. data/lib/faraday/file_part.rb +0 -128
  45. data/lib/faraday/logging/formatter.rb +0 -92
  46. data/lib/faraday/middleware_registry.rb +0 -129
  47. data/lib/faraday/options/connection_options.rb +0 -22
  48. data/lib/faraday/options/env.rb +0 -181
  49. data/lib/faraday/options/proxy_options.rb +0 -28
  50. data/lib/faraday/options/request_options.rb +0 -21
  51. data/lib/faraday/options/ssl_options.rb +0 -59
  52. data/lib/faraday/param_part.rb +0 -53
  53. data/lib/faraday/utils/headers.rb +0 -139
  54. data/lib/faraday/utils/params_hash.rb +0 -61
  55. data/spec/external_adapters/faraday_specs_setup.rb +0 -14
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Faraday
4
- # RequestOptions contains the configurable properties for a Faraday request.
5
- class RequestOptions < Options.new(:params_encoder, :proxy, :bind,
6
- :timeout, :open_timeout, :write_timeout,
7
- :boundary, :oauth, :context, :on_data)
8
-
9
- def []=(key, value)
10
- if key && key.to_sym == :proxy
11
- super(key, value ? ProxyOptions.from(value) : nil)
12
- else
13
- super(key, value)
14
- end
15
- end
16
-
17
- def stream_response?
18
- on_data.is_a?(Proc)
19
- end
20
- end
21
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Faraday
4
- # SSL-related options.
5
- #
6
- # @!attribute verify
7
- # @return [Boolean] whether to verify SSL certificates or not
8
- #
9
- # @!attribute ca_file
10
- # @return [String] CA file
11
- #
12
- # @!attribute ca_path
13
- # @return [String] CA path
14
- #
15
- # @!attribute verify_mode
16
- # @return [Integer] Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
17
- #
18
- # @!attribute cert_store
19
- # @return [OpenSSL::X509::Store] certificate store
20
- #
21
- # @!attribute client_cert
22
- # @return [String, OpenSSL::X509::Certificate] client certificate
23
- #
24
- # @!attribute client_key
25
- # @return [String, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA] client key
26
- #
27
- # @!attribute certificate
28
- # @return [OpenSSL::X509::Certificate] certificate (Excon only)
29
- #
30
- # @!attribute private_key
31
- # @return [OpenSSL::PKey::RSA, OpenSSL::PKey::DSA] private key (Excon only)
32
- #
33
- # @!attribute verify_depth
34
- # @return [Integer] maximum depth for the certificate chain verification
35
- #
36
- # @!attribute version
37
- # @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)
38
- #
39
- # @!attribute min_version
40
- # @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)
41
- #
42
- # @!attribute max_version
43
- # @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)
44
- class SSLOptions < Options.new(:verify, :ca_file, :ca_path, :verify_mode,
45
- :cert_store, :client_cert, :client_key,
46
- :certificate, :private_key, :verify_depth,
47
- :version, :min_version, :max_version)
48
-
49
- # @return [Boolean] true if should verify
50
- def verify?
51
- verify != false
52
- end
53
-
54
- # @return [Boolean] true if should not verify
55
- def disable?
56
- !verify?
57
- end
58
- end
59
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Faraday
4
- # Multipart value used to POST data with a content type.
5
- class ParamPart
6
- # @param value [String] Uploaded content as a String.
7
- # @param content_type [String] String content type of the value.
8
- # @param content_id [String] Optional String of this value's Content-ID.
9
- #
10
- # @return [Faraday::ParamPart]
11
- def initialize(value, content_type, content_id = nil)
12
- @value = value
13
- @content_type = content_type
14
- @content_id = content_id
15
- end
16
-
17
- # Converts this value to a form part.
18
- #
19
- # @param boundary [String] String multipart boundary that must not exist in
20
- # the content exactly.
21
- # @param key [String] String key name for this value.
22
- #
23
- # @return [Faraday::Parts::Part]
24
- def to_part(boundary, key)
25
- Faraday::Parts::Part.new(boundary, key, value, headers)
26
- end
27
-
28
- # Returns a Hash of String key/value pairs.
29
- #
30
- # @return [Hash]
31
- def headers
32
- {
33
- 'Content-Type' => content_type,
34
- 'Content-ID' => content_id
35
- }
36
- end
37
-
38
- # The content to upload.
39
- #
40
- # @return [String]
41
- attr_reader :value
42
-
43
- # The value's content type.
44
- #
45
- # @return [String]
46
- attr_reader :content_type
47
-
48
- # The value's content ID, if given.
49
- #
50
- # @return [String, nil]
51
- attr_reader :content_id
52
- end
53
- end
@@ -1,139 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Faraday
4
- module Utils
5
- # A case-insensitive Hash that preserves the original case of a header
6
- # when set.
7
- #
8
- # Adapted from Rack::Utils::HeaderHash
9
- class Headers < ::Hash
10
- def self.from(value)
11
- new(value)
12
- end
13
-
14
- def self.allocate
15
- new_self = super
16
- new_self.initialize_names
17
- new_self
18
- end
19
-
20
- def initialize(hash = nil)
21
- super()
22
- @names = {}
23
- update(hash || {})
24
- end
25
-
26
- def initialize_names
27
- @names = {}
28
- end
29
-
30
- # on dup/clone, we need to duplicate @names hash
31
- def initialize_copy(other)
32
- super
33
- @names = other.names.dup
34
- end
35
-
36
- # need to synchronize concurrent writes to the shared KeyMap
37
- keymap_mutex = Mutex.new
38
-
39
- # symbol -> string mapper + cache
40
- KeyMap = Hash.new do |map, key|
41
- value = if key.respond_to?(:to_str)
42
- key
43
- else
44
- key.to_s.split('_') # user_agent: %w(user agent)
45
- .each(&:capitalize!) # => %w(User Agent)
46
- .join('-') # => "User-Agent"
47
- end
48
- keymap_mutex.synchronize { map[key] = value }
49
- end
50
- KeyMap[:etag] = 'ETag'
51
-
52
- def [](key)
53
- key = KeyMap[key]
54
- super(key) || super(@names[key.downcase])
55
- end
56
-
57
- def []=(key, val)
58
- key = KeyMap[key]
59
- key = (@names[key.downcase] ||= key)
60
- # join multiple values with a comma
61
- val = val.to_ary.join(', ') if val.respond_to?(:to_ary)
62
- super(key, val)
63
- end
64
-
65
- def fetch(key, *args, &block)
66
- key = KeyMap[key]
67
- key = @names.fetch(key.downcase, key)
68
- super(key, *args, &block)
69
- end
70
-
71
- def delete(key)
72
- key = KeyMap[key]
73
- key = @names[key.downcase]
74
- return unless key
75
-
76
- @names.delete key.downcase
77
- super(key)
78
- end
79
-
80
- def include?(key)
81
- @names.include? key.downcase
82
- end
83
-
84
- alias has_key? include?
85
- alias member? include?
86
- alias key? include?
87
-
88
- def merge!(other)
89
- other.each { |k, v| self[k] = v }
90
- self
91
- end
92
-
93
- alias update merge!
94
-
95
- def merge(other)
96
- hash = dup
97
- hash.merge! other
98
- end
99
-
100
- def replace(other)
101
- clear
102
- @names.clear
103
- update other
104
- self
105
- end
106
-
107
- def to_hash
108
- ::Hash.new.update(self)
109
- end
110
-
111
- def parse(header_string)
112
- return unless header_string && !header_string.empty?
113
-
114
- headers = header_string.split(/\r\n/)
115
-
116
- # Find the last set of response headers.
117
- start_index = headers.rindex { |x| x.match(%r{^HTTP/}) } || 0
118
- last_response = headers.slice(start_index, headers.size)
119
-
120
- last_response
121
- .tap { |a| a.shift if a.first.start_with?('HTTP/') }
122
- .map { |h| h.split(/:\s*/, 2) } # split key and value
123
- .reject { |p| p[0].nil? } # ignore blank lines
124
- .each { |key, value| add_parsed(key, value) }
125
- end
126
-
127
- protected
128
-
129
- attr_reader :names
130
-
131
- private
132
-
133
- # Join multiple values with a comma.
134
- def add_parsed(key, value)
135
- self[key] ? self[key] << ', ' << value : self[key] = value
136
- end
137
- end
138
- end
139
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Faraday
4
- module Utils
5
- # A hash with stringified keys.
6
- class ParamsHash < Hash
7
- def [](key)
8
- super(convert_key(key))
9
- end
10
-
11
- def []=(key, value)
12
- super(convert_key(key), value)
13
- end
14
-
15
- def delete(key)
16
- super(convert_key(key))
17
- end
18
-
19
- def include?(key)
20
- super(convert_key(key))
21
- end
22
-
23
- alias has_key? include?
24
- alias member? include?
25
- alias key? include?
26
-
27
- def update(params)
28
- params.each do |key, value|
29
- self[key] = value
30
- end
31
- self
32
- end
33
- alias merge! update
34
-
35
- def merge(params)
36
- dup.update(params)
37
- end
38
-
39
- def replace(other)
40
- clear
41
- update(other)
42
- end
43
-
44
- def merge_query(query, encoder = nil)
45
- return self unless query && !query.empty?
46
-
47
- update((encoder || Utils.default_params_encoder).decode(query))
48
- end
49
-
50
- def to_query(encoder = nil)
51
- (encoder || Utils.default_params_encoder).encode(self)
52
- end
53
-
54
- private
55
-
56
- def convert_key(key)
57
- key.to_s
58
- end
59
- end
60
- end
61
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'webmock/rspec'
4
- WebMock.disable_net_connect!(allow_localhost: true)
5
-
6
- require_relative '../support/helper_methods'
7
- require_relative '../support/disabling_stub'
8
- require_relative '../support/streaming_response_checker'
9
- require_relative '../support/shared_examples/adapter'
10
- require_relative '../support/shared_examples/request_method'
11
-
12
- RSpec.configure do |config|
13
- config.include Faraday::HelperMethods
14
- end