Compare commits

...

10 Commits

Author SHA1 Message Date
Matt
43d6797770
Enables and fixes all new cops. (#1443) 2022-08-08 15:46:54 +01:00
Mattia Giuffrida
5e01af3828 Version bump to 2.5.1 2022-08-08 14:29:52 +01:00
Mattia Giuffrida
646c30b8cb Allow faraday-net_http up to v3.1
Version 3.0 of `faraday-net_http` uses the new streaming API and the new `finished` option in `save_response`, which are not available in `faraday` prior to version 2.5, and has therefore been released as a new major version.

To avoid the same issue in future, we're fixing the version to allow any 3.0.x version, but not 3.1+.
This will allow us to ship a minor versions of the adapter with "breaking" changes for older versions of Faraday.
2022-08-08 14:29:24 +01:00
Matt
591b58fc06
Version bump to 2.5.0 2022-08-08 12:29:03 +01:00
Sampat Badhe
1ddf062331
Fix documentation typo (#1441) 2022-08-08 12:26:02 +01:00
Mattia Giuffrida
1a5b794b88 Disable new streaming API specific tests 2022-08-08 12:23:09 +01:00
Mattia Giuffrida
8a6a12100d Update CI matrix:
* Make `truffleruby-head` experimental
* Add `ruby-head` as experimental
2022-08-08 12:23:09 +01:00
Mattia Giuffrida
6799f5852d Introduce new streaming API (#1439)
* Backwards-compatible
* Allow adapters to provide response info to on_call block
* Provide `stream_response` helper method
2022-08-08 12:23:09 +01:00
Mattia Giuffrida
5d4c1fb962 Temporarily use edge rubocop-packaging 2022-08-08 12:23:09 +01:00
Mattia Giuffrida
af116aa0a3 Add bake-test-external and test faraday-net_http as part of the CI 2022-08-08 12:23:09 +01:00
17 changed files with 200 additions and 144 deletions

View File

@ -40,7 +40,13 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ '2.6', '2.7', '3.0', '3.1', truffleruby-head ]
ruby: [ '2.6', '2.7', '3.0', '3.1' ]
experimental: [false]
include:
- ruby: head
experimental: true
- ruby: truffleruby-head
experimental: true
steps:
- uses: actions/checkout@v3
@ -49,7 +55,13 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Test
- name: RSpec
continue-on-error: ${{ matrix.experimental }}
run: bundle exec rake
- name: Test External Adapters
if: ${{ matrix.ruby != '2.6' }}
continue-on-error: ${{ matrix.experimental }}
run: bundle exec bake test:external

1
.gitignore vendored
View File

@ -14,6 +14,7 @@ tmp
.bundle
Gemfile.lock
vendor/bundle
external
## PROJECT::SPECIFIC
.rbx

View File

@ -9,193 +9,188 @@ AllCops:
DisplayStyleGuide: true
TargetRubyVersion: 2.6
Metrics/BlockLength:
Exclude:
- spec/**/*.rb
- examples/**/*.rb
Layout/EmptyLinesAroundAttributeAccessor: # (0.83)
Enabled: true
# Custom config
Gemspec/RequireMFA: # we don't know if this works with auto-deployments yet
Enabled: false
Layout/LineLength:
Exclude:
- spec/**/*.rb
- examples/**/*.rb
Layout/SpaceAroundMethodCallOperator:
Enabled: true
Lint/DeprecatedOpenSSLConstant: # (0.84)
Enabled: true
Lint/RaiseException:
Enabled: true
Lint/StructNewOverride:
Enabled: true
Style/DoubleNegation:
Enabled: false
Metrics/BlockLength:
Exclude:
- spec/**/*.rb
- examples/**/*.rb
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'examples/**/*'
Style/ExponentialNotation:
Enabled: true
Style/HashEachMethods:
Enabled: true
Style/HashTransformKeys:
Enabled: true
Style/HashTransformValues:
Enabled: true
Style/DoubleNegation:
Enabled: false
Style/IfUnlessModifier:
Enabled: false
Style/SlicingWithRange: # (0.83)
# New cops
Gemspec/DeprecatedAttributeAssignment: # new in 1.30
Enabled: true
Layout/BeginEndAlignment: # (new in 0.91)
Layout/LineContinuationLeadingSpace: # new in 1.31
Enabled: true
Lint/BinaryOperatorWithIdenticalOperands: # (new in 0.89)
Layout/LineContinuationSpacing: # new in 1.31
Enabled: true
Lint/ConstantDefinitionInBlock: # (new in 0.91)
Layout/LineEndStringConcatenationIndentation: # new in 1.18
Enabled: true
Lint/DuplicateElsifCondition: # (new in 0.88)
Layout/SpaceBeforeBrackets: # new in 1.7
Enabled: true
Lint/DuplicateRequire: # (new in 0.90)
Lint/AmbiguousAssignment: # new in 1.7
Enabled: true
Lint/DuplicateRescueException: # (new in 0.89)
Lint/AmbiguousOperatorPrecedence: # new in 1.21
Enabled: true
Lint/EmptyConditionalBody: # (new in 0.89)
Lint/AmbiguousRange: # new in 1.19
Enabled: true
Lint/EmptyFile: # (new in 0.90)
Lint/ConstantOverwrittenInRescue: # new in 1.31
Enabled: true
Lint/FloatComparison: # (new in 0.89)
Lint/DeprecatedConstants: # new in 1.8
Enabled: true
Lint/HashCompareByIdentity: # (new in 0.93)
Lint/DuplicateBranch: # new in 1.3
Enabled: true
Lint/IdentityComparison: # (new in 0.91)
Lint/DuplicateRegexpCharacterClassElement: # new in 1.1
Enabled: true
Lint/MissingSuper: # (new in 0.89)
Lint/EmptyBlock: # new in 1.1
Enabled: true
Lint/MixedRegexpCaptureTypes: # (new in 0.85)
Lint/EmptyClass: # new in 1.3
Enabled: true
Lint/OutOfRangeRegexpRef: # (new in 0.89)
Lint/EmptyInPattern: # new in 1.16
Enabled: true
Lint/RedundantSafeNavigation: # (new in 0.93)
Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
Enabled: true
Lint/SelfAssignment: # (new in 0.89)
Lint/LambdaWithoutLiteralBlock: # new in 1.8
Enabled: true
Lint/TopLevelReturnWithArgument: # (new in 0.89)
Lint/NoReturnInBeginEndBlocks: # new in 1.2
Enabled: true
Lint/TrailingCommaInAttributeDeclaration: # (new in 0.90)
Lint/NonAtomicFileOperation: # new in 1.31
Enabled: true
Performance/BlockGivenWithExplicitBlock: # (new in 1.9)
Lint/NumberedParameterAssignment: # new in 1.9
Enabled: true
Performance/CollectionLiteralInLoop: # (new in 1.8)
Lint/OrAssignmentToConstant: # new in 1.9
Enabled: true
Performance/ConstantRegexp: # (new in 1.9)
Lint/RedundantDirGlobSort: # new in 1.8
Enabled: true
Performance/MethodObjectAsBlock: # (new in 1.9)
Lint/RefinementImportMethods: # new in 1.27
Enabled: true
Performance/RedundantEqualityComparisonBlock: # (new in 1.10)
Lint/RequireRangeParentheses: # new in 1.32
Enabled: true
Performance/RedundantSortBlock: # (new in 1.7)
Lint/RequireRelativeSelfPath: # new in 1.22
Enabled: true
Performance/RedundantSplitRegexpArgument: # (new in 1.10)
Lint/SymbolConversion: # new in 1.9
Enabled: true
Performance/RedundantStringChars: # (new in 1.7)
Lint/ToEnumArguments: # new in 1.1
Enabled: true
Performance/ReverseFirst: # (new in 1.7)
Lint/TripleQuotes: # new in 1.9
Enabled: true
Performance/SortReverse: # (new in 1.7)
Lint/UnexpectedBlockArity: # new in 1.5
Enabled: true
Performance/Squeeze: # (new in 1.7)
Lint/UnmodifiedReduceAccumulator: # new in 1.1
Enabled: true
Performance/StringInclude: # (new in 1.7)
Lint/UselessRuby2Keywords: # new in 1.23
Enabled: true
Performance/Sum: # (new in 1.8)
Naming/BlockForwarding: # new in 1.24
Enabled: true
Gemspec/DeprecatedAttributeAssignment:
Security/CompoundHash: # new in 1.28
Enabled: true
Layout/LineEndStringConcatenationIndentation: # (new in 1.18)
Security/IoMethods: # new in 1.22
Enabled: true
Layout/SpaceBeforeBrackets: # (new in 1.7)
Style/ArgumentsForwarding: # new in 1.1
Enabled: true
Lint/AmbiguousAssignment: # (new in 1.7)
Style/CollectionCompact: # new in 1.2
Enabled: true
Lint/AmbiguousRange: # (new in 1.19)
Style/DocumentDynamicEvalDefinition: # new in 1.1
Enabled: true
Lint/DeprecatedConstants: # (new in 1.8)
Style/EmptyHeredoc: # new in 1.32
Enabled: true
Lint/DuplicateBranch: # (new in 1.3)
Style/EndlessMethod: # new in 1.8
Enabled: true
Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
Style/EnvHome: # new in 1.29
Enabled: true
Lint/EmptyBlock: # (new in 1.1)
Style/FetchEnvVar: # new in 1.28
Enabled: true
Lint/EmptyClass: # (new in 1.3)
Style/FileRead: # new in 1.24
Enabled: true
Lint/EmptyInPattern: # (new in 1.16)
Style/FileWrite: # new in 1.24
Enabled: true
Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
Style/HashConversion: # new in 1.10
Enabled: true
Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
Style/HashExcept: # new in 1.7
Enabled: true
Lint/NumberedParameterAssignment: # (new in 1.9)
Style/IfWithBooleanLiteralBranches: # new in 1.9
Enabled: true
Lint/OrAssignmentToConstant: # (new in 1.9)
Style/InPatternThen: # new in 1.16
Enabled: true
Lint/RedundantDirGlobSort: # (new in 1.8)
Style/MapCompactWithConditionalBlock: # new in 1.30
Enabled: true
Lint/SymbolConversion: # (new in 1.9)
Style/MapToHash: # new in 1.24
Enabled: true
Lint/ToEnumArguments: # (new in 1.1)
Style/MultilineInPatternThen: # new in 1.16
Enabled: true
Lint/TripleQuotes: # (new in 1.9)
Style/NegatedIfElseCondition: # new in 1.2
Enabled: true
Lint/UnexpectedBlockArity: # (new in 1.5)
Style/NestedFileDirname: # new in 1.26
Enabled: true
Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
Style/NilLambda: # new in 1.3
Enabled: true
Naming/InclusiveLanguage: # (new in 1.18)
Style/NumberedParameters: # new in 1.22
Enabled: true
Style/ArgumentsForwarding: # (new in 1.1)
Style/NumberedParametersLimit: # new in 1.22
Enabled: true
Style/CollectionCompact: # (new in 1.2)
Style/ObjectThen: # new in 1.28
Enabled: true
Style/DocumentDynamicEvalDefinition: # (new in 1.1)
Style/OpenStructUse: # new in 1.23
Enabled: true
Style/EndlessMethod: # (new in 1.8)
Style/QuotedSymbols: # new in 1.16
Enabled: true
Style/HashConversion: # (new in 1.10)
Style/RedundantArgument: # new in 1.4
Enabled: true
Style/HashExcept: # (new in 1.7)
Style/RedundantInitialize: # new in 1.27
Enabled: true
Style/IfWithBooleanLiteralBranches: # (new in 1.9)
Style/RedundantSelfAssignmentBranch: # new in 1.19
Enabled: true
Style/InPatternThen: # (new in 1.16)
Style/SelectByRegexp: # new in 1.22
Enabled: true
Style/MultilineInPatternThen: # (new in 1.16)
Style/StringChars: # new in 1.12
Enabled: true
Style/NegatedIfElseCondition: # (new in 1.2)
Style/SwapValues: # new in 1.1
Enabled: true
Style/NilLambda: # (new in 1.3)
Performance/AncestorsInclude: # new in 1.7
Enabled: true
Style/QuotedSymbols: # (new in 1.16)
Performance/BigDecimalWithNumericArgument: # new in 1.7
Enabled: true
Style/RedundantArgument: # (new in 1.4)
Performance/BlockGivenWithExplicitBlock: # new in 1.9
Enabled: true
Style/RedundantSelfAssignmentBranch: # (new in 1.19)
Performance/CollectionLiteralInLoop: # new in 1.8
Enabled: true
Style/StringChars: # (new in 1.12)
Performance/ConcurrentMonotonicTime: # new in 1.12
Enabled: true
Style/SwapValues: # (new in 1.1)
Performance/ConstantRegexp: # new in 1.9
Enabled: true
Performance/AncestorsInclude: # (new in 1.7)
Performance/MapCompact: # new in 1.11
Enabled: true
Performance/BigDecimalWithNumericArgument: # (new in 1.7)
Performance/MethodObjectAsBlock: # new in 1.9
Enabled: true
Performance/RedundantEqualityComparisonBlock: # new in 1.10
Enabled: true
Performance/RedundantSortBlock: # new in 1.7
Enabled: true
Performance/RedundantSplitRegexpArgument: # new in 1.10
Enabled: true
Performance/RedundantStringChars: # new in 1.7
Enabled: true
Performance/ReverseFirst: # new in 1.7
Enabled: true
Performance/SortReverse: # new in 1.7
Enabled: true
Performance/Squeeze: # new in 1.7
Enabled: true
Performance/StringIdentifierArgument: # new in 1.13
Enabled: true
Performance/StringInclude: # new in 1.7
Enabled: true
Performance/Sum: # new in 1.8
Enabled: true

View File

@ -1,17 +1,16 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-08-16 15:31:43 UTC using RuboCop version 1.19.0.
# on 2022-08-08 14:26:32 UTC using RuboCop version 1.33.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 7
# Offense count: 6
# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
Lint/ConstantDefinitionInBlock:
Exclude:
- 'spec/faraday/composite_read_io_spec.rb'
- 'spec/faraday/options/options_spec.rb'
- 'spec/faraday/rack_builder_spec.rb'
- 'spec/faraday/request/instrumentation_spec.rb'
@ -24,28 +23,33 @@ Lint/EmptyBlock:
- 'spec/faraday/rack_builder_spec.rb'
- 'spec/faraday/response_spec.rb'
# Offense count: 16
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
# Offense count: 12
# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 42
# Offense count: 3
# Offense count: 4
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 230
# Offense count: 12
# Configuration parameters: IgnoredMethods.
# Offense count: 9
# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 13
# Offense count: 27
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
# Offense count: 26
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
Metrics/MethodLength:
Max: 33
# Offense count: 8
# Configuration parameters: IgnoredMethods.
# Offense count: 1
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
Metrics/ParameterLists:
Max: 6
# Offense count: 6
# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
Metrics/PerceivedComplexity:
Max: 14
@ -54,4 +58,3 @@ Style/DocumentDynamicEvalDefinition:
Exclude:
- 'lib/faraday/connection.rb'
- 'lib/faraday/options.rb'

View File

@ -7,6 +7,7 @@ source 'https://rubygems.org'
gem 'jruby-openssl', '~> 0.11.0', platforms: :jruby
group :development, :test do
gem 'bake-test-external'
gem 'coveralls_reborn', require: false
gem 'pry'
gem 'rack', '~> 2.2'
@ -19,7 +20,7 @@ end
group :development, :lint do
gem 'rubocop'
gem 'rubocop-packaging', '~> 0.5'
gem 'rubocop-packaging', github: 'utkarsh2102/rubocop-packaging' # '~> 0.5'
gem 'rubocop-performance', '~> 1.0'
gem 'yard-junk'
end

3
config/external.yaml Normal file
View File

@ -0,0 +1,3 @@
faraday-net_http:
url: https://github.com/lostisland/faraday-net_http.git
command: bundle exec rspec

View File

@ -79,7 +79,7 @@ The default encoder is `Faraday::NestedParamsEncoder`.
### Order of parameters
By default, paramters are sorted by name while being serialized.
By default, parameters are sorted by name while being serialized.
Since this is really useful to provide better cache management and most servers don't really care about parameters order, this is the default behaviour.
However you might find yourself dealing with a server that requires parameters to be in a specific order.
When that happens, you can configure the encoder to skip sorting them.

View File

@ -22,9 +22,10 @@ This example implements such a callback:
streamed = []
conn.get('/stream/10') do |req|
# Set a callback which will receive tuples of chunk Strings
# and the sum of characters received so far
req.options.on_data = Proc.new do |chunk, overall_received_bytes|
# Set a callback which will receive tuples of chunk Strings,
# the sum of characters received so far, and the response environment.
# The latter will allow access to the response status, headers and reason, as well as the request info.
req.options.on_data = Proc.new do |chunk, overall_received_bytes, env|
puts "Received #{overall_received_bytes} characters"
streamed << chunk
end
@ -36,6 +37,8 @@ streamed.join
The `on_data` streaming is currently only supported by some adapters.
To see which ones, please refer to [Awesome Faraday][awesome] comparative table or check the adapter documentation.
Moreover, the `env` parameter was only recently added, which means some adapters may only have partial support
(i.e. only `chunk` and `overall_received_bytes` will be passed to your block).
[awesome]: https://github.com/lostisland/awesome-faraday/#adapters

View File

@ -15,7 +15,13 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.6'
spec.add_dependency 'faraday-net_http', '~> 2.0'
# faraday-net_http is the "default adapter", but being a Faraday dependency it can't
# control which version of faraday it will be pulled from.
# To avoid releasing a major version every time there's a new Faraday API, we should
# always fix its required version to the next MINOR version.
# This way, we can release minor versions of the adapter with "breaking" changes for older versions of Faraday
# and then bump the version requirement on the next compatible version of faraday.
spec.add_dependency 'faraday-net_http', '>= 2.0', '< 3.1'
spec.add_dependency 'ruby2_keywords', '>= 0.0.4'
# Includes `examples` and `spec` to allow external adapter gems to run Faraday unit and integration tests

View File

@ -59,7 +59,7 @@ module Faraday
private
def save_response(env, status, body, headers = nil, reason_phrase = nil)
def save_response(env, status, body, headers = nil, reason_phrase = nil, finished: true)
env.status = status
env.body = body
env.reason_phrase = reason_phrase&.to_s&.strip
@ -68,7 +68,7 @@ module Faraday
yield(response_headers) if block_given?
end
env.response.finish(env) unless env.parallel?
env.response.finish(env) unless env.parallel? || !finished
env.response
end

View File

@ -272,7 +272,7 @@ module Faraday
stub, meta = stubs.match(env)
unless stub
raise Stubs::NotFound, "no stubbed request for #{env[:method]} "\
raise Stubs::NotFound, "no stubbed request for #{env[:method]} " \
"#{env[:url]} #{env[:body]}"
end

View File

@ -537,7 +537,7 @@ module Faraday
end
def find_default_proxy
uri = ENV['http_proxy']
uri = ENV.fetch('http_proxy', nil)
return unless uri && !uri.empty?
uri = "http://#{uri}" unless uri.match?(/^http/i)

View File

@ -157,6 +157,24 @@ module Faraday
%(#<#{self.class}#{attrs.join(' ')}>)
end
def stream_response?
request.stream_response?
end
def stream_response(&block)
size = 0
yielded = false
block_result = block.call do |chunk| # rubocop:disable Performance/RedundantBlockCall
if chunk.bytesize.positive? || size.positive?
yielded = true
size += chunk.bytesize
request.on_data.call(chunk, size, self)
end
end
request.on_data.call(+'', 0, self) unless yielded
block_result
end
# @private
def custom_members
@custom_members ||= {}

View File

@ -1,5 +1,5 @@
# frozen_string_literal: true
module Faraday
VERSION = '2.4.0'
VERSION = '2.5.1'
end

View File

@ -6,7 +6,7 @@ class CustomEncoder
end
def decode(params)
params.split(',').map { |pair| pair.split('-') }.to_h
params.split(',').to_h { |pair| pair.split('-') }
end
end
@ -511,7 +511,7 @@ RSpec.describe Faraday::Connection do
it 'uses env http_proxy' do
with_env 'http_proxy' => 'http://proxy.com' do
conn = Faraday.new
expect(conn.instance_variable_get('@manual_proxy')).to be_falsey
expect(conn.instance_variable_get(:@manual_proxy)).to be_falsey
expect(conn.proxy_for_request('http://google.co.uk').host).to eq('proxy.com')
end
end
@ -519,7 +519,7 @@ RSpec.describe Faraday::Connection do
it 'uses processes no_proxy before http_proxy' do
with_env 'http_proxy' => 'http://proxy.com', 'no_proxy' => 'google.co.uk' do
conn = Faraday.new
expect(conn.instance_variable_get('@manual_proxy')).to be_falsey
expect(conn.instance_variable_get(:@manual_proxy)).to be_falsey
expect(conn.proxy_for_request('http://google.co.uk')).to be_nil
end
end
@ -527,7 +527,7 @@ RSpec.describe Faraday::Connection do
it 'uses env https_proxy' do
with_env 'https_proxy' => 'https://proxy.com' do
conn = Faraday.new
expect(conn.instance_variable_get('@manual_proxy')).to be_falsey
expect(conn.instance_variable_get(:@manual_proxy)).to be_falsey
expect(conn.proxy_for_request('https://google.co.uk').host).to eq('proxy.com')
end
end
@ -535,7 +535,7 @@ RSpec.describe Faraday::Connection do
it 'uses processes no_proxy before https_proxy' do
with_env 'https_proxy' => 'https://proxy.com', 'no_proxy' => 'google.co.uk' do
conn = Faraday.new
expect(conn.instance_variable_get('@manual_proxy')).to be_falsey
expect(conn.instance_variable_get(:@manual_proxy)).to be_falsey
expect(conn.proxy_for_request('https://google.co.uk')).to be_nil
end
end
@ -545,7 +545,7 @@ RSpec.describe Faraday::Connection do
conn = Faraday.new
conn.proxy = 'http://proxy2.com'
expect(conn.instance_variable_get('@manual_proxy')).to be_truthy
expect(conn.instance_variable_get(:@manual_proxy)).to be_truthy
expect(conn.proxy_for_request('https://google.co.uk').host).to eq('proxy2.com')
end
end
@ -580,7 +580,7 @@ RSpec.describe Faraday::Connection do
end
conn.get(url)
expect(conn.instance_variable_get('@temp_proxy')).to be_nil
expect(conn.instance_variable_get(:@temp_proxy)).to be_nil
end
it 'dynamically check no proxy' do

View File

@ -37,7 +37,7 @@ shared_examples 'adapter examples' do |**options|
let(:conn) do
conn_options[:ssl] ||= {}
conn_options[:ssl][:ca_file] ||= ENV['SSL_FILE']
conn_options[:ssl][:ca_file] ||= ENV.fetch('SSL_FILE', nil)
conn_options[:ssl][:verify_hostname] ||= ENV['SSL_VERIFY_HOSTNAME'] == 'yes'
Faraday.new(remote, conn_options) do |conn|

View File

@ -153,12 +153,19 @@ shared_examples 'a request method' do |http_method|
let(:streamed) { [] }
context 'when response is empty' do
it do
it 'handles streaming' do
env = nil
conn.public_send(http_method, '/') do |req|
req.options.on_data = proc { |*args| streamed << args }
req.options.on_data = proc do |chunk, size, block_env|
streamed << [chunk, size]
env ||= block_env
end
end
expect(streamed).to eq([['', 0]])
# TODO: enable this after updating all existing adapters to the new streaming API
# expect(env).to be_a(Faraday::Env)
# expect(env.status).to eq(200)
end
end
@ -166,12 +173,19 @@ shared_examples 'a request method' do |http_method|
before { request_stub.to_return(body: big_string) }
it 'handles streaming' do
env = nil
response = conn.public_send(http_method, '/') do |req|
req.options.on_data = proc { |*args| streamed << args }
req.options.on_data = proc do |chunk, size, block_env|
streamed << [chunk, size]
env ||= block_env
end
end
expect(response.body).to eq('')
check_streaming_response(streamed, chunk_size: 16 * 1024)
# TODO: enable this after updating all existing adapters to the new streaming API
# expect(env).to be_a(Faraday::Env)
# expect(env.status).to eq(200)
end
end
end