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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b9b61d836844815a4d9a5a1e9986c9a60416b8a9e9159d61f959e0c74ed52cc
4
- data.tar.gz: 34fb0b4f2d4a8b22a72d56d0f3d4bfa884b2290c5012b1cdfe6de4b6886420a6
3
+ metadata.gz: a991fd75b3b03d53636acde7819f2f2e4edd1ba9c43a2328083bfdc1a881e4b4
4
+ data.tar.gz: 7b30cf69876f689e09ae2128724a59f3e653d9e4a5963c5d77f4da2b4b200cac
5
5
  SHA512:
6
- metadata.gz: 9f0db04b8a845215b109b3491985dc6ce6ac60ced07874bcdcdd5bab5d935a40e51bda4feab6f93375889597185c295785e5a6d1119576762d006ca696033794
7
- data.tar.gz: 45debf037f0d1d02cccc70e33042c68d76146bb6b58bc8de839a7745404cd58a4171b0e209c75b1384475f6432531317a9145959ebf3ffe60837b65469f20e2b
6
+ metadata.gz: f1f24cae3a79cc5db4d5ac1968d46904f32759b3a7dc00e4f920c648867631f53451c5ec30fbaf982d23c6a57b64169c966a35b7ffb3892df265ff626d67d870
7
+ data.tar.gz: d07ec4f994e8440b4f762ff0e6d058508d891bca0bddf63f6270cc367b7b23d24c965c1c585be9d27687ef79df26d7688b484204db2b1ae8f8e555f364e5da45
@@ -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
 
@@ -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 ||= {}
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faraday
4
- VERSION = '2.4.0'
4
+ VERSION = '2.5.0'
5
5
  end
@@ -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 { |*args| streamed << args }
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 { |*args| streamed << args }
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.0
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-07-28 00:00:00.000000000 Z
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.4.0
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: