faraday 0.17.6 → 1.10.3

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 (135) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +156 -8
  3. data/LICENSE.md +1 -1
  4. data/README.md +16 -358
  5. data/Rakefile +1 -7
  6. data/examples/client_spec.rb +97 -0
  7. data/examples/client_test.rb +118 -0
  8. data/lib/faraday/adapter/test.rb +118 -69
  9. data/lib/faraday/adapter/typhoeus.rb +4 -1
  10. data/lib/faraday/adapter.rb +72 -22
  11. data/lib/faraday/adapter_registry.rb +30 -0
  12. data/lib/faraday/autoload.rb +39 -36
  13. data/lib/faraday/connection.rb +343 -185
  14. data/lib/faraday/dependency_loader.rb +39 -0
  15. data/lib/faraday/deprecate.rb +7 -6
  16. data/lib/faraday/encoders/flat_params_encoder.rb +105 -0
  17. data/lib/faraday/encoders/nested_params_encoder.rb +176 -0
  18. data/lib/faraday/error.rb +28 -40
  19. data/lib/faraday/logging/formatter.rb +105 -0
  20. data/lib/faraday/methods.rb +6 -0
  21. data/lib/faraday/middleware.rb +19 -25
  22. data/lib/faraday/middleware_registry.rb +129 -0
  23. data/lib/faraday/options/connection_options.rb +22 -0
  24. data/lib/faraday/options/env.rb +181 -0
  25. data/lib/faraday/options/proxy_options.rb +32 -0
  26. data/lib/faraday/options/request_options.rb +22 -0
  27. data/lib/faraday/options/ssl_options.rb +59 -0
  28. data/lib/faraday/options.rb +36 -191
  29. data/lib/faraday/parameters.rb +4 -197
  30. data/lib/faraday/rack_builder.rb +76 -64
  31. data/lib/faraday/request/authorization.rb +51 -30
  32. data/lib/faraday/request/basic_authentication.rb +14 -7
  33. data/lib/faraday/request/instrumentation.rb +45 -27
  34. data/lib/faraday/request/json.rb +55 -0
  35. data/lib/faraday/request/token_authentication.rb +15 -10
  36. data/lib/faraday/request/url_encoded.rb +43 -23
  37. data/lib/faraday/request.rb +82 -44
  38. data/lib/faraday/response/json.rb +54 -0
  39. data/lib/faraday/response/logger.rb +20 -69
  40. data/lib/faraday/response/raise_error.rb +49 -18
  41. data/lib/faraday/response.rb +26 -20
  42. data/lib/faraday/utils/headers.rb +139 -0
  43. data/lib/faraday/utils/params_hash.rb +61 -0
  44. data/lib/faraday/utils.rb +38 -247
  45. data/lib/faraday/version.rb +5 -0
  46. data/lib/faraday.rb +134 -188
  47. data/spec/external_adapters/faraday_specs_setup.rb +14 -0
  48. data/spec/faraday/adapter/em_http_spec.rb +49 -0
  49. data/spec/faraday/adapter/em_synchrony_spec.rb +18 -0
  50. data/spec/faraday/adapter/excon_spec.rb +49 -0
  51. data/spec/faraday/adapter/httpclient_spec.rb +73 -0
  52. data/spec/faraday/adapter/net_http_spec.rb +64 -0
  53. data/spec/faraday/adapter/patron_spec.rb +18 -0
  54. data/spec/faraday/adapter/rack_spec.rb +8 -0
  55. data/spec/faraday/adapter/test_spec.rb +377 -0
  56. data/spec/faraday/adapter/typhoeus_spec.rb +7 -0
  57. data/spec/faraday/adapter_registry_spec.rb +28 -0
  58. data/spec/faraday/adapter_spec.rb +55 -0
  59. data/spec/faraday/composite_read_io_spec.rb +80 -0
  60. data/spec/faraday/connection_spec.rb +736 -0
  61. data/spec/faraday/deprecate_spec.rb +17 -17
  62. data/spec/faraday/error_spec.rb +12 -54
  63. data/spec/faraday/middleware_spec.rb +52 -0
  64. data/spec/faraday/options/env_spec.rb +70 -0
  65. data/spec/faraday/options/options_spec.rb +297 -0
  66. data/spec/faraday/options/proxy_options_spec.rb +44 -0
  67. data/spec/faraday/options/request_options_spec.rb +19 -0
  68. data/spec/faraday/params_encoders/flat_spec.rb +42 -0
  69. data/spec/faraday/params_encoders/nested_spec.rb +142 -0
  70. data/spec/faraday/rack_builder_spec.rb +345 -0
  71. data/spec/faraday/request/authorization_spec.rb +96 -0
  72. data/spec/faraday/request/instrumentation_spec.rb +76 -0
  73. data/spec/faraday/request/json_spec.rb +111 -0
  74. data/spec/faraday/request/url_encoded_spec.rb +83 -0
  75. data/spec/faraday/request_spec.rb +120 -0
  76. data/spec/faraday/response/json_spec.rb +119 -0
  77. data/spec/faraday/response/logger_spec.rb +220 -0
  78. data/spec/faraday/response/middleware_spec.rb +68 -0
  79. data/spec/faraday/response/raise_error_spec.rb +78 -15
  80. data/spec/faraday/response_spec.rb +75 -0
  81. data/spec/faraday/utils/headers_spec.rb +82 -0
  82. data/spec/faraday/utils_spec.rb +56 -0
  83. data/spec/faraday_spec.rb +37 -0
  84. data/spec/spec_helper.rb +65 -36
  85. data/spec/support/disabling_stub.rb +14 -0
  86. data/spec/support/fake_safe_buffer.rb +15 -0
  87. data/spec/support/helper_methods.rb +133 -0
  88. data/spec/support/shared_examples/adapter.rb +105 -0
  89. data/spec/support/shared_examples/params_encoder.rb +18 -0
  90. data/spec/support/shared_examples/request_method.rb +262 -0
  91. data/spec/support/streaming_response_checker.rb +35 -0
  92. data/spec/support/webmock_rack_app.rb +68 -0
  93. metadata +210 -56
  94. data/lib/faraday/adapter/em_http.rb +0 -243
  95. data/lib/faraday/adapter/em_http_ssl_patch.rb +0 -56
  96. data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +0 -66
  97. data/lib/faraday/adapter/em_synchrony.rb +0 -106
  98. data/lib/faraday/adapter/excon.rb +0 -82
  99. data/lib/faraday/adapter/httpclient.rb +0 -128
  100. data/lib/faraday/adapter/net_http.rb +0 -153
  101. data/lib/faraday/adapter/net_http_persistent.rb +0 -68
  102. data/lib/faraday/adapter/patron.rb +0 -95
  103. data/lib/faraday/adapter/rack.rb +0 -58
  104. data/lib/faraday/request/multipart.rb +0 -68
  105. data/lib/faraday/request/retry.rb +0 -213
  106. data/lib/faraday/upload_io.rb +0 -77
  107. data/test/adapters/default_test.rb +0 -14
  108. data/test/adapters/em_http_test.rb +0 -30
  109. data/test/adapters/em_synchrony_test.rb +0 -32
  110. data/test/adapters/excon_test.rb +0 -30
  111. data/test/adapters/httpclient_test.rb +0 -34
  112. data/test/adapters/integration.rb +0 -263
  113. data/test/adapters/logger_test.rb +0 -136
  114. data/test/adapters/net_http_persistent_test.rb +0 -114
  115. data/test/adapters/net_http_test.rb +0 -79
  116. data/test/adapters/patron_test.rb +0 -40
  117. data/test/adapters/rack_test.rb +0 -38
  118. data/test/adapters/test_middleware_test.rb +0 -157
  119. data/test/adapters/typhoeus_test.rb +0 -38
  120. data/test/authentication_middleware_test.rb +0 -65
  121. data/test/composite_read_io_test.rb +0 -109
  122. data/test/connection_test.rb +0 -738
  123. data/test/env_test.rb +0 -268
  124. data/test/helper.rb +0 -75
  125. data/test/live_server.rb +0 -67
  126. data/test/middleware/instrumentation_test.rb +0 -88
  127. data/test/middleware/retry_test.rb +0 -282
  128. data/test/middleware_stack_test.rb +0 -260
  129. data/test/multibyte.txt +0 -1
  130. data/test/options_test.rb +0 -333
  131. data/test/parameters_test.rb +0 -157
  132. data/test/request_middleware_test.rb +0 -126
  133. data/test/response_middleware_test.rb +0 -72
  134. data/test/strawberry.rb +0 -2
  135. data/test/utils_test.rb +0 -98
@@ -1,58 +0,0 @@
1
- module Faraday
2
- class Adapter
3
- # Sends requests to a Rack app.
4
- #
5
- # Examples
6
- #
7
- # class MyRackApp
8
- # def call(env)
9
- # [200, {'Content-Type' => 'text/html'}, ["hello world"]]
10
- # end
11
- # end
12
- #
13
- # Faraday.new do |conn|
14
- # conn.adapter :rack, MyRackApp.new
15
- # end
16
- class Rack < Faraday::Adapter
17
- dependency 'rack/test'
18
-
19
- # not prefixed with "HTTP_"
20
- SPECIAL_HEADERS = %w[ CONTENT_LENGTH CONTENT_TYPE ]
21
-
22
- def initialize(faraday_app, rack_app)
23
- super(faraday_app)
24
- mock_session = ::Rack::MockSession.new(rack_app)
25
- @session = ::Rack::Test::Session.new(mock_session)
26
- end
27
-
28
- def call(env)
29
- super
30
- rack_env = {
31
- :method => env[:method],
32
- :input => env[:body].respond_to?(:read) ? env[:body].read : env[:body],
33
- 'rack.url_scheme' => env[:url].scheme
34
- }
35
-
36
- env[:request_headers].each do |name, value|
37
- name = name.upcase.tr('-', '_')
38
- name = "HTTP_#{name}" unless SPECIAL_HEADERS.include? name
39
- rack_env[name] = value
40
- end if env[:request_headers]
41
-
42
- timeout = env[:request][:timeout] || env[:request][:open_timeout]
43
- response = if timeout
44
- Timer.timeout(timeout, Faraday::TimeoutError) { execute_request(env, rack_env) }
45
- else
46
- execute_request(env, rack_env)
47
- end
48
-
49
- save_response(env, response.status, response.body, response.headers)
50
- @app.call env
51
- end
52
-
53
- def execute_request(env, rack_env)
54
- @session.request(env[:url].to_s, rack_env)
55
- end
56
- end
57
- end
58
- end
@@ -1,68 +0,0 @@
1
- require File.expand_path("../url_encoded", __FILE__)
2
- require 'securerandom'
3
-
4
- module Faraday
5
- class Request::Multipart < Request::UrlEncoded
6
- self.mime_type = 'multipart/form-data'.freeze
7
- DEFAULT_BOUNDARY_PREFIX = "-----------RubyMultipartPost".freeze unless defined? DEFAULT_BOUNDARY_PREFIX
8
-
9
- def call(env)
10
- match_content_type(env) do |params|
11
- env.request.boundary ||= unique_boundary
12
- env.request_headers[CONTENT_TYPE] += "; boundary=#{env.request.boundary}"
13
- env.body = create_multipart(env, params)
14
- end
15
- @app.call env
16
- end
17
-
18
- def process_request?(env)
19
- type = request_type(env)
20
- env.body.respond_to?(:each_key) and !env.body.empty? and (
21
- (type.empty? and has_multipart?(env.body)) or
22
- type == self.class.mime_type
23
- )
24
- end
25
-
26
- def has_multipart?(obj)
27
- # string is an enum in 1.8, returning list of itself
28
- if obj.respond_to?(:each) && !obj.is_a?(String)
29
- (obj.respond_to?(:values) ? obj.values : obj).each do |val|
30
- return true if (val.respond_to?(:content_type) || has_multipart?(val))
31
- end
32
- end
33
- false
34
- end
35
-
36
- def create_multipart(env, params)
37
- boundary = env.request.boundary
38
- parts = process_params(params) do |key, value|
39
- Faraday::Parts::Part.new(boundary, key, value)
40
- end
41
- parts << Faraday::Parts::EpiloguePart.new(boundary)
42
-
43
- body = Faraday::CompositeReadIO.new(parts)
44
- env.request_headers[Faraday::Env::ContentLength] = body.length.to_s
45
- return body
46
- end
47
-
48
- def unique_boundary
49
- "#{DEFAULT_BOUNDARY_PREFIX}-#{SecureRandom.hex}"
50
- end
51
-
52
- def process_params(params, prefix = nil, pieces = nil, &block)
53
- params.inject(pieces || []) do |all, (key, value)|
54
- key = "#{prefix}[#{key}]" if prefix
55
-
56
- case value
57
- when Array
58
- values = value.inject([]) { |a,v| a << [nil, v] }
59
- process_params(values, key, all, &block)
60
- when Hash
61
- process_params(value, key, all, &block)
62
- else
63
- all << block.call(key, value)
64
- end
65
- end
66
- end
67
- end
68
- end
@@ -1,213 +0,0 @@
1
- require 'date'
2
-
3
- module Faraday
4
- # Catches exceptions and retries each request a limited number of times.
5
- #
6
- # By default, it retries 2 times and handles only timeout exceptions. It can
7
- # be configured with an arbitrary number of retries, a list of exceptions to
8
- # handle, a retry interval, a percentage of randomness to add to the retry
9
- # interval, and a backoff factor.
10
- #
11
- # Examples
12
- #
13
- # Faraday.new do |conn|
14
- # conn.request :retry, max: 2, interval: 0.05,
15
- # interval_randomness: 0.5, backoff_factor: 2,
16
- # exceptions: [CustomException, 'Timeout::Error']
17
- # conn.adapter ...
18
- # end
19
- #
20
- # This example will result in a first interval that is random between 0.05 and 0.075 and a second
21
- # interval that is random between 0.1 and 0.15
22
- #
23
- class Request::Retry < Faraday::Middleware
24
- DEFAULT_EXCEPTIONS = [Errno::ETIMEDOUT, 'Timeout::Error',
25
- Faraday::TimeoutError, Faraday::RetriableResponse
26
- ].freeze
27
- IDEMPOTENT_METHODS = [:delete, :get, :head, :options, :put]
28
-
29
- class Options < Faraday::Options.new(:max, :interval, :max_interval, :interval_randomness,
30
- :backoff_factor, :exceptions, :methods, :retry_if, :retry_block,
31
- :retry_statuses)
32
-
33
- DEFAULT_CHECK = lambda { |env,exception| false }
34
-
35
- def self.from(value)
36
- if Integer === value
37
- new(value)
38
- else
39
- super(value)
40
- end
41
- end
42
-
43
- def max
44
- (self[:max] ||= 2).to_i
45
- end
46
-
47
- def interval
48
- (self[:interval] ||= 0).to_f
49
- end
50
-
51
- def max_interval
52
- (self[:max_interval] ||= Float::MAX).to_f
53
- end
54
-
55
- def interval_randomness
56
- (self[:interval_randomness] ||= 0).to_f
57
- end
58
-
59
- def backoff_factor
60
- (self[:backoff_factor] ||= 1).to_f
61
- end
62
-
63
- def exceptions
64
- Array(self[:exceptions] ||= DEFAULT_EXCEPTIONS)
65
- end
66
-
67
- def methods
68
- Array(self[:methods] ||= IDEMPOTENT_METHODS)
69
- end
70
-
71
- def retry_if
72
- self[:retry_if] ||= DEFAULT_CHECK
73
- end
74
-
75
- def retry_block
76
- self[:retry_block] ||= Proc.new {}
77
- end
78
-
79
- def retry_statuses
80
- Array(self[:retry_statuses] ||= [])
81
- end
82
- end
83
-
84
- # Public: Initialize middleware
85
- #
86
- # Options:
87
- # max - Maximum number of retries (default: 2)
88
- # interval - Pause in seconds between retries (default: 0)
89
- # interval_randomness - The maximum random interval amount expressed
90
- # as a float between 0 and 1 to use in addition to the
91
- # interval. (default: 0)
92
- # max_interval - An upper limit for the interval (default: Float::MAX)
93
- # backoff_factor - The amount to multiple each successive retry's
94
- # interval amount by in order to provide backoff
95
- # (default: 1)
96
- # exceptions - The list of exceptions to handle. Exceptions can be
97
- # given as Class, Module, or String. (default:
98
- # [Errno::ETIMEDOUT, 'Timeout::Error',
99
- # Faraday::TimeoutError, Faraday::RetriableResponse])
100
- # methods - A list of HTTP methods to retry without calling retry_if. Pass
101
- # an empty Array to call retry_if for all exceptions.
102
- # (defaults to the idempotent HTTP methods in IDEMPOTENT_METHODS)
103
- # retry_if - block that will receive the env object and the exception raised
104
- # and should decide if the code should retry still the action or
105
- # not independent of the retry count. This would be useful
106
- # if the exception produced is non-recoverable or if the
107
- # the HTTP method called is not idempotent.
108
- # (defaults to return false)
109
- # retry_block - block that is executed after every retry. Request environment, middleware options,
110
- # current number of retries and the exception is passed to the block as parameters.
111
- def initialize(app, options = nil)
112
- super(app)
113
- @options = Options.from(options)
114
- @errmatch = build_exception_matcher(@options.exceptions)
115
- end
116
-
117
- def calculate_sleep_amount(retries, env)
118
- retry_after = calculate_retry_after(env)
119
- retry_interval = calculate_retry_interval(retries)
120
-
121
- return if retry_after && retry_after > @options.max_interval
122
-
123
- retry_after && retry_after >= retry_interval ? retry_after : retry_interval
124
- end
125
-
126
- def call(env)
127
- retries = @options.max
128
- request_body = env[:body]
129
- begin
130
- env[:body] = request_body # after failure env[:body] is set to the response body
131
- @app.call(env).tap do |resp|
132
- raise Faraday::RetriableResponse.new(nil, resp) if @options.retry_statuses.include?(resp.status)
133
- end
134
- rescue @errmatch => exception
135
- if retries > 0 && retry_request?(env, exception)
136
- retries -= 1
137
- rewind_files(request_body)
138
- @options.retry_block.call(env, @options, retries, exception)
139
- if (sleep_amount = calculate_sleep_amount(retries + 1, env))
140
- sleep sleep_amount
141
- retry
142
- end
143
- end
144
-
145
- if exception.is_a?(Faraday::RetriableResponse)
146
- exception.response
147
- else
148
- raise
149
- end
150
- end
151
- end
152
-
153
- # Private: construct an exception matcher object.
154
- #
155
- # An exception matcher for the rescue clause can usually be any object that
156
- # responds to `===`, but for Ruby 1.8 it has to be a Class or Module.
157
- def build_exception_matcher(exceptions)
158
- matcher = Module.new
159
- (class << matcher; self; end).class_eval do
160
- define_method(:===) do |error|
161
- exceptions.any? do |ex|
162
- if ex.is_a? Module
163
- error.is_a? ex
164
- else
165
- error.class.to_s == ex.to_s
166
- end
167
- end
168
- end
169
- end
170
- matcher
171
- end
172
-
173
- private
174
-
175
- def retry_request?(env, exception)
176
- @options.methods.include?(env[:method]) || @options.retry_if.call(env, exception)
177
- end
178
-
179
- def rewind_files(body)
180
- return unless body.is_a?(Hash)
181
- body.each do |_, value|
182
- if value.is_a? UploadIO
183
- value.rewind
184
- end
185
- end
186
- end
187
-
188
- # MDN spec for Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
189
- def calculate_retry_after(env)
190
- response_headers = env[:response_headers]
191
- return unless response_headers
192
-
193
- retry_after_value = env[:response_headers]["Retry-After"]
194
-
195
- # Try to parse date from the header value
196
- begin
197
- datetime = DateTime.rfc2822(retry_after_value)
198
- datetime.to_time - Time.now.utc
199
- rescue ArgumentError
200
- retry_after_value.to_f
201
- end
202
- end
203
-
204
- def calculate_retry_interval(retries)
205
- retry_index = @options.max - retries
206
- current_interval = @options.interval * (@options.backoff_factor ** retry_index)
207
- current_interval = [current_interval, @options.max_interval].min
208
- random_interval = rand * @options.interval_randomness.to_f * @options.interval
209
-
210
- current_interval + random_interval
211
- end
212
- end
213
- end
@@ -1,77 +0,0 @@
1
- begin
2
- require 'multipart/post'
3
- require 'stringio'
4
- rescue LoadError
5
- begin
6
- require 'composite_io'
7
- require 'parts'
8
- require 'stringio'
9
- rescue LoadError
10
- $stderr.puts "Install the multipart-post gem."
11
- raise
12
- end
13
- end
14
-
15
- module Faraday
16
- # Similar but not compatible with ::CompositeReadIO provided by multipart-post.
17
- class CompositeReadIO
18
- def initialize(*parts)
19
- @parts = parts.flatten
20
- @ios = @parts.map { |part| part.to_io }
21
- @index = 0
22
- end
23
-
24
- def length
25
- @parts.inject(0) { |sum, part| sum + part.length }
26
- end
27
-
28
- def rewind
29
- @ios.each { |io| io.rewind }
30
- @index = 0
31
- end
32
-
33
- # Read from IOs in order until `length` bytes have been received.
34
- def read(length = nil, outbuf = nil)
35
- got_result = false
36
- outbuf = outbuf ? outbuf.replace("") : ""
37
-
38
- while io = current_io
39
- if result = io.read(length)
40
- got_result ||= !result.nil?
41
- result.force_encoding("BINARY") if result.respond_to?(:force_encoding)
42
- outbuf << result
43
- length -= result.length if length
44
- break if length == 0
45
- end
46
- advance_io
47
- end
48
- (!got_result && length) ? nil : outbuf
49
- end
50
-
51
- def close
52
- @ios.each { |io| io.close }
53
- end
54
-
55
- def ensure_open_and_readable
56
- # Rubinius compatibility
57
- end
58
-
59
- private
60
-
61
- def current_io
62
- @ios[@index]
63
- end
64
-
65
- def advance_io
66
- @index += 1
67
- end
68
- end
69
-
70
- if defined?(::Multipart::Post::UploadIO)
71
- UploadIO = ::Multipart::Post::UploadIO
72
- Parts = ::Multipart::Post::Parts
73
- else
74
- UploadIO = ::UploadIO
75
- Parts = ::Parts
76
- end
77
- end
@@ -1,14 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class DefaultTest < Faraday::TestCase
5
-
6
- def adapter() :default end
7
-
8
- Integration.apply(self, :NonParallel) do
9
- # default stack is not configured with Multipart
10
- undef :test_POST_sends_files
11
- end
12
-
13
- end
14
- end
@@ -1,30 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class EMHttpTest < Faraday::TestCase
5
-
6
- def adapter() :em_http end
7
-
8
- Integration.apply(self, :Parallel) do
9
- # https://github.com/eventmachine/eventmachine/pull/289
10
- undef :test_timeout
11
-
12
- def test_binds_local_socket
13
- host = '1.2.3.4'
14
- conn = create_connection :request => { :bind => { :host => host } }
15
- assert_equal host, conn.options[:bind][:host]
16
- end
17
- end unless jruby? and ssl_mode?
18
- # https://github.com/eventmachine/eventmachine/issues/180
19
-
20
- def test_custom_adapter_config
21
- url = URI('https://example.com:1234')
22
-
23
- adapter = Faraday::Adapter::EMHttp.new nil, inactivity_timeout: 20
24
-
25
- req = adapter.create_request(url: url, request: {})
26
-
27
- assert_equal 20, req.connopts.inactivity_timeout
28
- end
29
- end
30
- end
@@ -1,32 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class EMSynchronyTest < Faraday::TestCase
5
-
6
- def adapter() :em_synchrony end
7
-
8
- unless jruby?
9
- Integration.apply(self, :Parallel) do
10
- # https://github.com/eventmachine/eventmachine/pull/289
11
- undef :test_timeout
12
-
13
- def test_binds_local_socket
14
- host = '1.2.3.4'
15
- conn = create_connection :request => { :bind => { :host => host } }
16
- #put conn.get('/who-am-i').body
17
- assert_equal host, conn.options[:bind][:host]
18
- end
19
- end
20
- end
21
-
22
- def test_custom_adapter_config
23
- url = URI('https://example.com:1234')
24
-
25
- adapter = Faraday::Adapter::EMSynchrony.new nil, inactivity_timeout: 20
26
-
27
- req = adapter.create_request(url: url, request: {})
28
-
29
- assert_equal 20, req.connopts.inactivity_timeout
30
- end
31
- end
32
- end
@@ -1,30 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class ExconTest < Faraday::TestCase
5
-
6
- def adapter() :excon end
7
-
8
- Integration.apply(self, :NonParallel) do
9
- # https://github.com/geemus/excon/issues/126 ?
10
- undef :test_timeout if ssl_mode?
11
-
12
- # Excon lets OpenSSL::SSL::SSLError be raised without any way to
13
- # distinguish whether it happened because of a 407 proxy response
14
- undef :test_proxy_auth_fail if ssl_mode?
15
-
16
- # https://github.com/geemus/excon/issues/358
17
- undef :test_connection_error if RUBY_VERSION >= '2.1.0'
18
- end
19
-
20
- def test_custom_adapter_config
21
- url = URI('https://example.com:1234')
22
-
23
- adapter = Faraday::Adapter::Excon.new nil, debug_request: true
24
-
25
- conn = adapter.create_connection({url: url}, {})
26
-
27
- assert_equal true, conn.data[:debug_request]
28
- end
29
- end
30
- end
@@ -1,34 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class HttpclientTest < Faraday::TestCase
5
-
6
- def adapter() :httpclient end
7
-
8
- Integration.apply(self, :NonParallel, :Compression) do
9
- def setup
10
- require 'httpclient' unless defined?(HTTPClient)
11
- HTTPClient::NO_PROXY_HOSTS.delete('localhost')
12
- end
13
-
14
- def test_binds_local_socket
15
- host = '1.2.3.4'
16
- conn = create_connection :request => { :bind => { :host => host } }
17
- assert_equal host, conn.options[:bind][:host]
18
- end
19
-
20
- def test_custom_adapter_config
21
- adapter = Faraday::Adapter::HTTPClient.new do |client|
22
- client.keep_alive_timeout = 20
23
- client.ssl_config.timeout = 25
24
- end
25
-
26
- client = adapter.client
27
- adapter.configure_client
28
-
29
- assert_equal 20, client.keep_alive_timeout
30
- assert_equal 25, client.ssl_config.timeout
31
- end
32
- end
33
- end
34
- end