Compare commits

..

No commits in common. "43d67977708d98cda0f47a3fc4f6f9a224cbd921" and "7f444c397142388707d70a3d14dde8c3dbdcad71" have entirely different histories.

17 changed files with 144 additions and 200 deletions

View File

@ -40,13 +40,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
ruby: [ '2.6', '2.7', '3.0', '3.1' ] ruby: [ '2.6', '2.7', '3.0', '3.1', truffleruby-head ]
experimental: [false]
include:
- ruby: head
experimental: true
- ruby: truffleruby-head
experimental: true
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@ -55,13 +49,7 @@ jobs:
ruby-version: ${{ matrix.ruby }} ruby-version: ${{ matrix.ruby }}
bundler-cache: true bundler-cache: true
- name: RSpec - name: Test
continue-on-error: ${{ matrix.experimental }} continue-on-error: ${{ matrix.experimental }}
run: bundle exec rake 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,7 +14,6 @@ tmp
.bundle .bundle
Gemfile.lock Gemfile.lock
vendor/bundle vendor/bundle
external
## PROJECT::SPECIFIC ## PROJECT::SPECIFIC
.rbx .rbx

View File

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

View File

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

View File

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

View File

@ -1,3 +0,0 @@
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 ### Order of parameters
By default, parameters are sorted by name while being serialized. By default, paramters 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. 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. 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. When that happens, you can configure the encoder to skip sorting them.

View File

@ -22,10 +22,9 @@ This example implements such a callback:
streamed = [] streamed = []
conn.get('/stream/10') do |req| conn.get('/stream/10') do |req|
# Set a callback which will receive tuples of chunk Strings, # Set a callback which will receive tuples of chunk Strings
# the sum of characters received so far, and the response environment. # and the sum of characters received so far
# 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|
req.options.on_data = Proc.new do |chunk, overall_received_bytes, env|
puts "Received #{overall_received_bytes} characters" puts "Received #{overall_received_bytes} characters"
streamed << chunk streamed << chunk
end end
@ -37,8 +36,6 @@ streamed.join
The `on_data` streaming is currently only supported by some adapters. 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. 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 [awesome]: https://github.com/lostisland/awesome-faraday/#adapters

View File

@ -15,13 +15,7 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.6' spec.required_ruby_version = '>= 2.6'
# faraday-net_http is the "default adapter", but being a Faraday dependency it can't spec.add_dependency 'faraday-net_http', '~> 2.0'
# 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' spec.add_dependency 'ruby2_keywords', '>= 0.0.4'
# Includes `examples` and `spec` to allow external adapter gems to run Faraday unit and integration tests # 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 private
def save_response(env, status, body, headers = nil, reason_phrase = nil, finished: true) def save_response(env, status, body, headers = nil, reason_phrase = nil)
env.status = status env.status = status
env.body = body env.body = body
env.reason_phrase = reason_phrase&.to_s&.strip env.reason_phrase = reason_phrase&.to_s&.strip
@ -68,7 +68,7 @@ module Faraday
yield(response_headers) if block_given? yield(response_headers) if block_given?
end end
env.response.finish(env) unless env.parallel? || !finished env.response.finish(env) unless env.parallel?
env.response env.response
end end

View File

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

View File

@ -157,24 +157,6 @@ module Faraday
%(#<#{self.class}#{attrs.join(' ')}>) %(#<#{self.class}#{attrs.join(' ')}>)
end 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 # @private
def custom_members def custom_members
@custom_members ||= {} @custom_members ||= {}

View File

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

View File

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

View File

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

View File

@ -153,19 +153,12 @@ shared_examples 'a request method' do |http_method|
let(:streamed) { [] } let(:streamed) { [] }
context 'when response is empty' do context 'when response is empty' do
it 'handles streaming' do it do
env = nil
conn.public_send(http_method, '/') do |req| conn.public_send(http_method, '/') do |req|
req.options.on_data = proc do |chunk, size, block_env| req.options.on_data = proc { |*args| streamed << args }
streamed << [chunk, size]
env ||= block_env
end
end end
expect(streamed).to eq([['', 0]]) 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
end end
@ -173,19 +166,12 @@ shared_examples 'a request method' do |http_method|
before { request_stub.to_return(body: big_string) } before { request_stub.to_return(body: big_string) }
it 'handles streaming' do it 'handles streaming' do
env = nil
response = conn.public_send(http_method, '/') do |req| response = conn.public_send(http_method, '/') do |req|
req.options.on_data = proc do |chunk, size, block_env| req.options.on_data = proc { |*args| streamed << args }
streamed << [chunk, size]
env ||= block_env
end
end end
expect(response.body).to eq('') expect(response.body).to eq('')
check_streaming_response(streamed, chunk_size: 16 * 1024) 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 end
end end