faraday 2.7.1 → 2.7.4
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/LICENSE.md +1 -1
- data/README.md +9 -9
- data/lib/faraday/adapter/test.rb +17 -4
- data/lib/faraday/adapter.rb +1 -2
- data/lib/faraday/connection.rb +9 -10
- data/lib/faraday/logging/formatter.rb +5 -5
- data/lib/faraday/options/env.rb +13 -7
- data/lib/faraday/response/logger.rb +2 -2
- data/lib/faraday/response.rb +2 -1
- data/lib/faraday/version.rb +1 -1
- data/spec/faraday/adapter/test_spec.rb +29 -0
- data/spec/faraday/connection_spec.rb +15 -0
- data/spec/faraday/response/logger_spec.rb +1 -1
- data/spec/faraday/response_spec.rb +3 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: acdabcdd0a13d304292f17cd6764fba01d12f552cf78bdae3006ee38a3921ad0
|
|
4
|
+
data.tar.gz: 13300a1971d6557a4c62f01c4b0c96d1aecb4372b4c8a1ba734022109d9f2c0b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0151023e942ae76b69a6bb28e70c792501333bc4f67c670bb990e80917c6b4d63aaa9ee168bd333abff2dd2b1fb54f244568e7a54d5346034d311924b17eabfe
|
|
7
|
+
data.tar.gz: 9598f16ed0c19cdfe01be90a1a29e6751b6848d44eac1d481224fbe576a33ff73f631a2bd398f70b5534d4126f8dba9ced68bb17dad5ea8efe93214bf7ce4e1b
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
[](https://github.com/lostisland/faraday/actions?query=workflow%3ACI)
|
|
5
5
|
[](https://github.com/lostisland/faraday/discussions)
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
Faraday is an HTTP client library abstraction layer that provides a common interface over many
|
|
9
8
|
adapters (such as Net::HTTP) and embraces the concept of Rack middleware when processing the request/response cycle.
|
|
10
9
|
You probably don't want to use Faraday directly in your project, as it will lack an actual client library to perform
|
|
@@ -42,14 +41,15 @@ Open the issues page and check for the `help wanted` label!
|
|
|
42
41
|
But before you start coding, please read our [Contributing Guide][contributing]
|
|
43
42
|
|
|
44
43
|
## Copyright
|
|
45
|
-
© 2009 - 2022, the [Faraday Team][faraday_team]. Website and branding design by [Elena Lo Piccolo](https://elelopic.design).
|
|
46
44
|
|
|
47
|
-
[
|
|
48
|
-
|
|
45
|
+
© 2009 - 2023, the [Faraday Team][faraday_team]. Website and branding design by [Elena Lo Piccolo](https://elelopic.design).
|
|
46
|
+
|
|
47
|
+
[awesome]: https://github.com/lostisland/awesome-faraday/#adapters
|
|
48
|
+
[website]: https://lostisland.github.io/faraday
|
|
49
49
|
[faraday_team]: https://lostisland.github.io/faraday/team
|
|
50
50
|
[contributing]: https://github.com/lostisland/faraday/blob/master/.github/CONTRIBUTING.md
|
|
51
|
-
[apidoc]:
|
|
52
|
-
[actions]:
|
|
53
|
-
[jruby]:
|
|
54
|
-
[rubinius]:
|
|
55
|
-
[license]:
|
|
51
|
+
[apidoc]: https://www.rubydoc.info/github/lostisland/faraday
|
|
52
|
+
[actions]: https://github.com/lostisland/faraday/actions
|
|
53
|
+
[jruby]: http://jruby.org/
|
|
54
|
+
[rubinius]: http://rubini.us/
|
|
55
|
+
[license]: LICENSE.md
|
data/lib/faraday/adapter/test.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'timeout'
|
|
4
|
+
|
|
3
5
|
module Faraday
|
|
4
6
|
class Adapter
|
|
5
7
|
# @example
|
|
@@ -238,7 +240,7 @@ module Faraday
|
|
|
238
240
|
end
|
|
239
241
|
|
|
240
242
|
def body_match?(request_body)
|
|
241
|
-
return true if body.to_s.
|
|
243
|
+
return true if body.to_s.empty?
|
|
242
244
|
|
|
243
245
|
case body
|
|
244
246
|
when Proc
|
|
@@ -277,11 +279,22 @@ module Faraday
|
|
|
277
279
|
end
|
|
278
280
|
|
|
279
281
|
block_arity = stub.block.arity
|
|
282
|
+
params = if block_arity >= 0
|
|
283
|
+
[env, meta].take(block_arity)
|
|
284
|
+
else
|
|
285
|
+
[env, meta]
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
timeout = request_timeout(:open, env[:request])
|
|
289
|
+
timeout ||= request_timeout(:read, env[:request])
|
|
290
|
+
|
|
280
291
|
status, headers, body =
|
|
281
|
-
if
|
|
282
|
-
|
|
292
|
+
if timeout
|
|
293
|
+
::Timeout.timeout(timeout, Faraday::TimeoutError) do
|
|
294
|
+
stub.block.call(*params)
|
|
295
|
+
end
|
|
283
296
|
else
|
|
284
|
-
stub.block.call(
|
|
297
|
+
stub.block.call(*params)
|
|
285
298
|
end
|
|
286
299
|
|
|
287
300
|
# We need to explicitly pass `reason_phrase = nil` here to avoid keyword args conflicts.
|
data/lib/faraday/adapter.rb
CHANGED
|
@@ -78,8 +78,7 @@ module Faraday
|
|
|
78
78
|
# @param type [Symbol] Describes which timeout setting to get: :read,
|
|
79
79
|
# :write, or :open.
|
|
80
80
|
# @param options [Hash] Hash containing Symbol keys like :timeout,
|
|
81
|
-
# :read_timeout, :write_timeout, :open_timeout
|
|
82
|
-
# :timeout
|
|
81
|
+
# :read_timeout, :write_timeout, or :open_timeout
|
|
83
82
|
#
|
|
84
83
|
# @return [Integer, nil] Timeout duration in seconds, or nil if no timeout
|
|
85
84
|
# has been set.
|
data/lib/faraday/connection.rb
CHANGED
|
@@ -220,7 +220,7 @@ module Faraday
|
|
|
220
220
|
# @yield [Faraday::Request] for further request customizations
|
|
221
221
|
# @return [Faraday::Response]
|
|
222
222
|
def options(*args)
|
|
223
|
-
return @options if args.
|
|
223
|
+
return @options if args.empty?
|
|
224
224
|
|
|
225
225
|
url, params, headers = *args
|
|
226
226
|
run_request(:options, url, nil, headers) do |request|
|
|
@@ -261,14 +261,13 @@ module Faraday
|
|
|
261
261
|
# @param headers [Hash, nil] unencoded HTTP header key/value pairs.
|
|
262
262
|
#
|
|
263
263
|
# @example
|
|
264
|
-
#
|
|
265
|
-
# conn.post '/items', data, content_type: 'application/json'
|
|
264
|
+
# conn.put '/products/123', data, content_type: 'application/json'
|
|
266
265
|
#
|
|
267
|
-
# #
|
|
268
|
-
# conn.
|
|
269
|
-
# req.headers[
|
|
270
|
-
# req.
|
|
271
|
-
# req.
|
|
266
|
+
# # Star a gist.
|
|
267
|
+
# conn.put 'https://api.github.com/gists/GIST_ID/star' do |req|
|
|
268
|
+
# req.headers['Accept'] = 'application/vnd.github+json'
|
|
269
|
+
# req.headers['Authorization'] = 'Bearer <YOUR-TOKEN>'
|
|
270
|
+
# req.headers['X-GitHub-Api-Version'] = '2022-11-28'
|
|
272
271
|
# end
|
|
273
272
|
#
|
|
274
273
|
# @yield [Faraday::Request] for further request customizations
|
|
@@ -471,10 +470,10 @@ module Faraday
|
|
|
471
470
|
def build_exclusive_url(url = nil, params = nil, params_encoder = nil)
|
|
472
471
|
url = nil if url.respond_to?(:empty?) && url.empty?
|
|
473
472
|
base = url_prefix.dup
|
|
474
|
-
if url && base.path
|
|
473
|
+
if url && !base.path.end_with?('/')
|
|
475
474
|
base.path = "#{base.path}/" # ensure trailing slash
|
|
476
475
|
end
|
|
477
|
-
url = url.to_s.gsub(':', '%3A') if
|
|
476
|
+
url = url.to_s.gsub(':', '%3A') if URI.parse(url.to_s).opaque
|
|
478
477
|
uri = url ? base + url : base
|
|
479
478
|
if params
|
|
480
479
|
uri.query = params.to_query(params_encoder || options.params_encoder)
|
|
@@ -37,16 +37,16 @@ module Faraday
|
|
|
37
37
|
log_body('response', env[:body]) if env[:body] && log_body?(:response)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
def
|
|
40
|
+
def exception(exc)
|
|
41
41
|
return unless log_errors?
|
|
42
42
|
|
|
43
|
-
error_log = proc {
|
|
43
|
+
error_log = proc { exc.full_message }
|
|
44
44
|
public_send(log_level, 'error', &error_log)
|
|
45
45
|
|
|
46
|
-
log_headers('error',
|
|
47
|
-
return unless
|
|
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
48
|
|
|
49
|
-
log_body('error',
|
|
49
|
+
log_body('error', exc.response_body)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def filter(filter_word, filter_replacement)
|
data/lib/faraday/options/env.rb
CHANGED
|
@@ -15,13 +15,19 @@ module Faraday
|
|
|
15
15
|
# @return [Hash] options for configuring the request.
|
|
16
16
|
# Options for configuring the request.
|
|
17
17
|
#
|
|
18
|
-
# - `:timeout`
|
|
19
|
-
#
|
|
20
|
-
# - `:
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
18
|
+
# - `:timeout` - time limit for the entire request (Integer in
|
|
19
|
+
# seconds)
|
|
20
|
+
# - `:open_timeout` - time limit for just the connection phase (e.g.
|
|
21
|
+
# handshake) (Integer in seconds)
|
|
22
|
+
# - `:read_timeout` - time limit for the first response byte received from
|
|
23
|
+
# the server (Integer in seconds)
|
|
24
|
+
# - `:write_timeout` - time limit for the client to send the request to the
|
|
25
|
+
# server (Integer in seconds)
|
|
26
|
+
# - `:on_data` - Proc for streaming
|
|
27
|
+
# - `:proxy` - Hash of proxy options
|
|
28
|
+
# - `:uri` - Proxy server URI
|
|
29
|
+
# - `:user` - Proxy server username
|
|
30
|
+
# - `:password` - Proxy server password
|
|
25
31
|
#
|
|
26
32
|
# @!attribute request_headers
|
|
27
33
|
# @return [Hash] HTTP Headers to be sent to the server.
|
data/lib/faraday/response.rb
CHANGED
data/lib/faraday/version.rb
CHANGED
|
@@ -410,4 +410,33 @@ RSpec.describe Faraday::Adapter::Test do
|
|
|
410
410
|
end
|
|
411
411
|
end
|
|
412
412
|
end
|
|
413
|
+
|
|
414
|
+
describe 'request timeout' do
|
|
415
|
+
subject(:request) do
|
|
416
|
+
connection.get('/sleep') do |req|
|
|
417
|
+
req.options.timeout = timeout
|
|
418
|
+
end
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
before do
|
|
422
|
+
stubs.get('/sleep') do
|
|
423
|
+
sleep(0.01)
|
|
424
|
+
[200, {}, '']
|
|
425
|
+
end
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
context 'when request is within timeout' do
|
|
429
|
+
let(:timeout) { 1 }
|
|
430
|
+
|
|
431
|
+
it { expect(request.status).to eq 200 }
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
context 'when request is too slow' do
|
|
435
|
+
let(:timeout) { 0.001 }
|
|
436
|
+
|
|
437
|
+
it 'raises an exception' do
|
|
438
|
+
expect { request }.to raise_error(Faraday::TimeoutError)
|
|
439
|
+
end
|
|
440
|
+
end
|
|
441
|
+
end
|
|
413
442
|
end
|
|
@@ -310,6 +310,21 @@ RSpec.describe Faraday::Connection do
|
|
|
310
310
|
expect(uri.to_s).to eq('http://service.com/api/service%3Asearch?limit=400')
|
|
311
311
|
end
|
|
312
312
|
end
|
|
313
|
+
|
|
314
|
+
context 'with a custom `default_uri_parser`' do
|
|
315
|
+
let(:url) { 'http://httpbingo.org' }
|
|
316
|
+
let(:parser) { Addressable::URI }
|
|
317
|
+
|
|
318
|
+
around do |example|
|
|
319
|
+
with_default_uri_parser(parser) do
|
|
320
|
+
example.run
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
it 'does not raise error' do
|
|
325
|
+
expect { conn.build_exclusive_url('/nigiri') }.not_to raise_error
|
|
326
|
+
end
|
|
327
|
+
end
|
|
313
328
|
end
|
|
314
329
|
|
|
315
330
|
describe '#build_url' do
|
|
@@ -68,7 +68,7 @@ RSpec.describe Faraday::Response::Logger do
|
|
|
68
68
|
context 'when no route' do
|
|
69
69
|
it 'delegates logging to the formatter' do
|
|
70
70
|
expect(formatter).to receive(:request).with(an_instance_of(Faraday::Env))
|
|
71
|
-
expect(formatter).to receive(:
|
|
71
|
+
expect(formatter).to receive(:exception).with(an_instance_of(Faraday::Adapter::Test::Stubs::NotFound))
|
|
72
72
|
|
|
73
73
|
expect { conn.get '/noroute' }.to raise_error(Faraday::Adapter::Test::Stubs::NotFound)
|
|
74
74
|
end
|
|
@@ -4,7 +4,7 @@ RSpec.describe Faraday::Response do
|
|
|
4
4
|
subject { Faraday::Response.new(env) }
|
|
5
5
|
|
|
6
6
|
let(:env) do
|
|
7
|
-
Faraday::Env.from(status: 404, body: 'yikes',
|
|
7
|
+
Faraday::Env.from(status: 404, body: 'yikes', url: Faraday::Utils.URI('https://lostisland.github.io/faraday'),
|
|
8
8
|
response_headers: { 'Content-Type' => 'text/plain' })
|
|
9
9
|
end
|
|
10
10
|
|
|
@@ -30,6 +30,7 @@ RSpec.describe Faraday::Response do
|
|
|
30
30
|
it { expect(hash[:status]).to eq(subject.status) }
|
|
31
31
|
it { expect(hash[:response_headers]).to eq(subject.headers) }
|
|
32
32
|
it { expect(hash[:body]).to eq(subject.body) }
|
|
33
|
+
it { expect(hash[:url]).to eq(subject.env.url) }
|
|
33
34
|
end
|
|
34
35
|
|
|
35
36
|
describe 'marshal serialization support' do
|
|
@@ -45,6 +46,7 @@ RSpec.describe Faraday::Response do
|
|
|
45
46
|
it { expect(loaded.env[:body]).to eq(env[:body]) }
|
|
46
47
|
it { expect(loaded.env[:response_headers]).to eq(env[:response_headers]) }
|
|
47
48
|
it { expect(loaded.env[:status]).to eq(env[:status]) }
|
|
49
|
+
it { expect(loaded.env[:url]).to eq(env[:url]) }
|
|
48
50
|
end
|
|
49
51
|
|
|
50
52
|
describe '#on_complete' do
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: faraday
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.7.
|
|
4
|
+
version: 2.7.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- "@technoweenie"
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2023-01-20 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: faraday-net_http
|
|
@@ -131,7 +131,7 @@ licenses:
|
|
|
131
131
|
- MIT
|
|
132
132
|
metadata:
|
|
133
133
|
homepage_uri: https://lostisland.github.io/faraday
|
|
134
|
-
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.7.
|
|
134
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.7.4
|
|
135
135
|
source_code_uri: https://github.com/lostisland/faraday
|
|
136
136
|
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
|
137
137
|
post_install_message:
|