faraday 2.4.0 → 2.5.2
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/lib/faraday/adapter/test.rb +6 -2
- data/lib/faraday/adapter.rb +2 -2
- data/lib/faraday/connection.rb +1 -1
- data/lib/faraday/options/env.rb +18 -0
- data/lib/faraday/version.rb +1 -1
- data/spec/faraday/connection_spec.rb +7 -7
- data/spec/support/shared_examples/adapter.rb +1 -1
- data/spec/support/shared_examples/request_method.rb +17 -3
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5bf37c33313ee7027a44ba34906e46285c4bf4c51205f58e3ad50c0d5b7a3ab
|
4
|
+
data.tar.gz: 1bc57e0e2909550e60575320fbaa4bb75d17e914462ed57d06fe2cccd81804fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed0374b593a768aad905cf1c175cc86fc0892757a3b549def26e09a84016ffd6674d8e920e6c14b7709bf505a3b0a682b0191b2239b4eefe1f09ce23fad999b2
|
7
|
+
data.tar.gz: 59ce275bfb56375648ee5966e0fd2b7326117bd2d62789533d4856021a2c6a96f859f813dc4c9b472cd0c7579fa38765ba027193b69352a6e4740e21fd0bc3b8
|
data/lib/faraday/adapter/test.rb
CHANGED
@@ -272,7 +272,7 @@ module Faraday
|
|
272
272
|
stub, meta = stubs.match(env)
|
273
273
|
|
274
274
|
unless stub
|
275
|
-
raise Stubs::NotFound, "no stubbed request for #{env[:method]} "\
|
275
|
+
raise Stubs::NotFound, "no stubbed request for #{env[:method]} " \
|
276
276
|
"#{env[:url]} #{env[:body]}"
|
277
277
|
end
|
278
278
|
|
@@ -283,7 +283,11 @@ module Faraday
|
|
283
283
|
else
|
284
284
|
stub.block.call(env, meta)
|
285
285
|
end
|
286
|
-
|
286
|
+
|
287
|
+
# We need to explicitly pass `reason_phrase = nil` here to avoid keyword args conflicts.
|
288
|
+
# See https://github.com/lostisland/faraday/issues/1444
|
289
|
+
# TODO: remove `nil` explicit reason_phrase once Ruby 3.0 becomes minimum req. version
|
290
|
+
save_response(env, status, body, headers, nil)
|
287
291
|
|
288
292
|
@app.call(env)
|
289
293
|
end
|
data/lib/faraday/adapter.rb
CHANGED
@@ -59,7 +59,7 @@ module Faraday
|
|
59
59
|
|
60
60
|
private
|
61
61
|
|
62
|
-
def save_response(env, status, body, headers = nil, reason_phrase = nil)
|
62
|
+
def save_response(env, status, body, headers = nil, reason_phrase = nil, finished: true)
|
63
63
|
env.status = status
|
64
64
|
env.body = body
|
65
65
|
env.reason_phrase = reason_phrase&.to_s&.strip
|
@@ -68,7 +68,7 @@ module Faraday
|
|
68
68
|
yield(response_headers) if block_given?
|
69
69
|
end
|
70
70
|
|
71
|
-
env.response.finish(env) unless env.parallel?
|
71
|
+
env.response.finish(env) unless env.parallel? || !finished
|
72
72
|
env.response
|
73
73
|
end
|
74
74
|
|
data/lib/faraday/connection.rb
CHANGED
data/lib/faraday/options/env.rb
CHANGED
@@ -157,6 +157,24 @@ module Faraday
|
|
157
157
|
%(#<#{self.class}#{attrs.join(' ')}>)
|
158
158
|
end
|
159
159
|
|
160
|
+
def stream_response?
|
161
|
+
request.stream_response?
|
162
|
+
end
|
163
|
+
|
164
|
+
def stream_response(&block)
|
165
|
+
size = 0
|
166
|
+
yielded = false
|
167
|
+
block_result = block.call do |chunk| # rubocop:disable Performance/RedundantBlockCall
|
168
|
+
if chunk.bytesize.positive? || size.positive?
|
169
|
+
yielded = true
|
170
|
+
size += chunk.bytesize
|
171
|
+
request.on_data.call(chunk, size, self)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
request.on_data.call(+'', 0, self) unless yielded
|
175
|
+
block_result
|
176
|
+
end
|
177
|
+
|
160
178
|
# @private
|
161
179
|
def custom_members
|
162
180
|
@custom_members ||= {}
|
data/lib/faraday/version.rb
CHANGED
@@ -6,7 +6,7 @@ class CustomEncoder
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def decode(params)
|
9
|
-
params.split(',').
|
9
|
+
params.split(',').to_h { |pair| pair.split('-') }
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -511,7 +511,7 @@ RSpec.describe Faraday::Connection do
|
|
511
511
|
it 'uses env http_proxy' do
|
512
512
|
with_env 'http_proxy' => 'http://proxy.com' do
|
513
513
|
conn = Faraday.new
|
514
|
-
expect(conn.instance_variable_get(
|
514
|
+
expect(conn.instance_variable_get(:@manual_proxy)).to be_falsey
|
515
515
|
expect(conn.proxy_for_request('http://google.co.uk').host).to eq('proxy.com')
|
516
516
|
end
|
517
517
|
end
|
@@ -519,7 +519,7 @@ RSpec.describe Faraday::Connection do
|
|
519
519
|
it 'uses processes no_proxy before http_proxy' do
|
520
520
|
with_env 'http_proxy' => 'http://proxy.com', 'no_proxy' => 'google.co.uk' do
|
521
521
|
conn = Faraday.new
|
522
|
-
expect(conn.instance_variable_get(
|
522
|
+
expect(conn.instance_variable_get(:@manual_proxy)).to be_falsey
|
523
523
|
expect(conn.proxy_for_request('http://google.co.uk')).to be_nil
|
524
524
|
end
|
525
525
|
end
|
@@ -527,7 +527,7 @@ RSpec.describe Faraday::Connection do
|
|
527
527
|
it 'uses env https_proxy' do
|
528
528
|
with_env 'https_proxy' => 'https://proxy.com' do
|
529
529
|
conn = Faraday.new
|
530
|
-
expect(conn.instance_variable_get(
|
530
|
+
expect(conn.instance_variable_get(:@manual_proxy)).to be_falsey
|
531
531
|
expect(conn.proxy_for_request('https://google.co.uk').host).to eq('proxy.com')
|
532
532
|
end
|
533
533
|
end
|
@@ -535,7 +535,7 @@ RSpec.describe Faraday::Connection do
|
|
535
535
|
it 'uses processes no_proxy before https_proxy' do
|
536
536
|
with_env 'https_proxy' => 'https://proxy.com', 'no_proxy' => 'google.co.uk' do
|
537
537
|
conn = Faraday.new
|
538
|
-
expect(conn.instance_variable_get(
|
538
|
+
expect(conn.instance_variable_get(:@manual_proxy)).to be_falsey
|
539
539
|
expect(conn.proxy_for_request('https://google.co.uk')).to be_nil
|
540
540
|
end
|
541
541
|
end
|
@@ -545,7 +545,7 @@ RSpec.describe Faraday::Connection do
|
|
545
545
|
conn = Faraday.new
|
546
546
|
conn.proxy = 'http://proxy2.com'
|
547
547
|
|
548
|
-
expect(conn.instance_variable_get(
|
548
|
+
expect(conn.instance_variable_get(:@manual_proxy)).to be_truthy
|
549
549
|
expect(conn.proxy_for_request('https://google.co.uk').host).to eq('proxy2.com')
|
550
550
|
end
|
551
551
|
end
|
@@ -580,7 +580,7 @@ RSpec.describe Faraday::Connection do
|
|
580
580
|
end
|
581
581
|
|
582
582
|
conn.get(url)
|
583
|
-
expect(conn.instance_variable_get(
|
583
|
+
expect(conn.instance_variable_get(:@temp_proxy)).to be_nil
|
584
584
|
end
|
585
585
|
|
586
586
|
it 'dynamically check no proxy' do
|
@@ -37,7 +37,7 @@ shared_examples 'adapter examples' do |**options|
|
|
37
37
|
|
38
38
|
let(:conn) do
|
39
39
|
conn_options[:ssl] ||= {}
|
40
|
-
conn_options[:ssl][:ca_file] ||= ENV
|
40
|
+
conn_options[:ssl][:ca_file] ||= ENV.fetch('SSL_FILE', nil)
|
41
41
|
conn_options[:ssl][:verify_hostname] ||= ENV['SSL_VERIFY_HOSTNAME'] == 'yes'
|
42
42
|
|
43
43
|
Faraday.new(remote, conn_options) do |conn|
|
@@ -153,12 +153,19 @@ shared_examples 'a request method' do |http_method|
|
|
153
153
|
let(:streamed) { [] }
|
154
154
|
|
155
155
|
context 'when response is empty' do
|
156
|
-
it do
|
156
|
+
it 'handles streaming' do
|
157
|
+
env = nil
|
157
158
|
conn.public_send(http_method, '/') do |req|
|
158
|
-
req.options.on_data = proc
|
159
|
+
req.options.on_data = proc do |chunk, size, block_env|
|
160
|
+
streamed << [chunk, size]
|
161
|
+
env ||= block_env
|
162
|
+
end
|
159
163
|
end
|
160
164
|
|
161
165
|
expect(streamed).to eq([['', 0]])
|
166
|
+
# TODO: enable this after updating all existing adapters to the new streaming API
|
167
|
+
# expect(env).to be_a(Faraday::Env)
|
168
|
+
# expect(env.status).to eq(200)
|
162
169
|
end
|
163
170
|
end
|
164
171
|
|
@@ -166,12 +173,19 @@ shared_examples 'a request method' do |http_method|
|
|
166
173
|
before { request_stub.to_return(body: big_string) }
|
167
174
|
|
168
175
|
it 'handles streaming' do
|
176
|
+
env = nil
|
169
177
|
response = conn.public_send(http_method, '/') do |req|
|
170
|
-
req.options.on_data = proc
|
178
|
+
req.options.on_data = proc do |chunk, size, block_env|
|
179
|
+
streamed << [chunk, size]
|
180
|
+
env ||= block_env
|
181
|
+
end
|
171
182
|
end
|
172
183
|
|
173
184
|
expect(response.body).to eq('')
|
174
185
|
check_streaming_response(streamed, chunk_size: 16 * 1024)
|
186
|
+
# TODO: enable this after updating all existing adapters to the new streaming API
|
187
|
+
# expect(env).to be_a(Faraday::Env)
|
188
|
+
# expect(env.status).to eq(200)
|
175
189
|
end
|
176
190
|
end
|
177
191
|
end
|
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.
|
4
|
+
version: 2.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@technoweenie"
|
@@ -10,22 +10,28 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-08-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday-net_http
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - "
|
19
|
+
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '2.0'
|
22
|
+
- - "<"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '3.1'
|
22
25
|
type: :runtime
|
23
26
|
prerelease: false
|
24
27
|
version_requirements: !ruby/object:Gem::Requirement
|
25
28
|
requirements:
|
26
|
-
- - "
|
29
|
+
- - ">="
|
27
30
|
- !ruby/object:Gem::Version
|
28
31
|
version: '2.0'
|
32
|
+
- - "<"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.1'
|
29
35
|
- !ruby/object:Gem::Dependency
|
30
36
|
name: ruby2_keywords
|
31
37
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,7 +131,7 @@ licenses:
|
|
125
131
|
- MIT
|
126
132
|
metadata:
|
127
133
|
homepage_uri: https://lostisland.github.io/faraday
|
128
|
-
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.
|
134
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.5.2
|
129
135
|
source_code_uri: https://github.com/lostisland/faraday
|
130
136
|
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
131
137
|
post_install_message:
|