Merge pull request #478 from jrafanie/dup_names_hash_when_copying_header_hash

Dup the @names hash when the Headers hash is copied.
This commit is contained in:
Mislav Marohnić 2015-10-03 01:56:07 +02:00
commit ac73c46a78
2 changed files with 26 additions and 0 deletions

View File

@ -17,6 +17,12 @@ module Faraday
self.update(hash || {})
end
# on dup/clone, we need to duplicate @names hash
def initialize_copy(other)
super
@names = other.names.dup
end
# need to synchronize concurrent writes to the shared KeyMap
keymap_mutex = Mutex.new
@ -102,6 +108,12 @@ module Faraday
end
}
end
protected
def names
@names
end
end
# hash with stringified keys

View File

@ -200,6 +200,20 @@ class TestConnection < Faraday::TestCase
assert_equal "http://sushi.com/nigiri?a=1&b=2&c=3", url.to_s
end
def test_request_header_change_does_not_modify_connection_header
connection = Faraday.new(:url => "https://asushi.com/sake.html")
connection.headers = { "Authorization"=>"token abc123" }
request = connection.build_request(:get)
request.headers.delete("Authorization")
assert_equal connection.headers.keys.sort, ["Authorization"]
assert connection.headers.include?("Authorization")
assert_equal request.headers.keys.sort, []
assert !request.headers.include?("Authorization")
end
def test_env_url_parses_url_params_into_query
uri = env_url("http://sushi.com/sake.html", 'a[b]' => '1 + 2')
assert_equal "a%5Bb%5D=1+%2B+2", uri.query