mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-08 00:03:41 -04:00
Fix thread safety issue by avoiding mutation of proxy options hash (#1617)
This commit is contained in:
parent
1551c32371
commit
cd1c44a4aa
@ -22,8 +22,10 @@ module Faraday
|
||||
when URI
|
||||
value = { uri: value }
|
||||
when Hash, Options
|
||||
if (uri = value.delete(:uri))
|
||||
value[:uri] = Utils.URI(uri)
|
||||
if value[:uri]
|
||||
value = value.dup.tap do |duped|
|
||||
duped[:uri] = Utils.URI(duped[:uri])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -27,6 +27,33 @@ RSpec.describe Faraday::ProxyOptions do
|
||||
expect(options.inspect).to eq('#<Faraday::ProxyOptions (empty)>')
|
||||
end
|
||||
|
||||
it 'works with hash' do
|
||||
hash = { user: 'user', password: 'pass', uri: 'http://@example.org' }
|
||||
options = Faraday::ProxyOptions.from(hash)
|
||||
expect(options.user).to eq('user')
|
||||
expect(options.password).to eq('pass')
|
||||
expect(options.uri).to be_a_kind_of(URI)
|
||||
expect(options.path).to eq('')
|
||||
expect(options.port).to eq(80)
|
||||
expect(options.host).to eq('example.org')
|
||||
expect(options.scheme).to eq('http')
|
||||
expect(options.inspect).to match('#<Faraday::ProxyOptions uri=')
|
||||
end
|
||||
|
||||
it 'works with option' do
|
||||
opt_arg = { user: 'user', password: 'pass', uri: 'http://@example.org' }
|
||||
option = Faraday::ConnectionOptions.from(proxy: opt_arg)
|
||||
options = Faraday::ProxyOptions.from(option.proxy)
|
||||
expect(options.user).to eq('user')
|
||||
expect(options.password).to eq('pass')
|
||||
expect(options.uri).to be_a_kind_of(URI)
|
||||
expect(options.path).to eq('')
|
||||
expect(options.port).to eq(80)
|
||||
expect(options.host).to eq('example.org')
|
||||
expect(options.scheme).to eq('http')
|
||||
expect(options.inspect).to match('#<Faraday::ProxyOptions uri=')
|
||||
end
|
||||
|
||||
it 'works with no auth' do
|
||||
proxy = Faraday::ProxyOptions.from 'http://example.org'
|
||||
expect(proxy.user).to be_nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user