faraday 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/faraday/adapter.rb +2 -2
- data/lib/faraday/options/env.rb +18 -0
- data/lib/faraday/version.rb +1 -1
- data/spec/support/shared_examples/request_method.rb +17 -3
- 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: a991fd75b3b03d53636acde7819f2f2e4edd1ba9c43a2328083bfdc1a881e4b4
|
4
|
+
data.tar.gz: 7b30cf69876f689e09ae2128724a59f3e653d9e4a5963c5d77f4da2b4b200cac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1f24cae3a79cc5db4d5ac1968d46904f32759b3a7dc00e4f920c648867631f53451c5ec30fbaf982d23c6a57b64169c966a35b7ffb3892df265ff626d67d870
|
7
|
+
data.tar.gz: d07ec4f994e8440b4f762ff0e6d058508d891bca0bddf63f6270cc367b7b23d24c965c1c585be9d27687ef79df26d7688b484204db2b1ae8f8e555f364e5da45
|
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/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
@@ -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.0
|
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: 2022-
|
13
|
+
date: 2022-08-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday-net_http
|
@@ -125,7 +125,7 @@ licenses:
|
|
125
125
|
- MIT
|
126
126
|
metadata:
|
127
127
|
homepage_uri: https://lostisland.github.io/faraday
|
128
|
-
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.
|
128
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.5.0
|
129
129
|
source_code_uri: https://github.com/lostisland/faraday
|
130
130
|
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
131
131
|
post_install_message:
|