1
0
Fork 0
mirror of https://github.com/rest-client/rest-client.git synced 2022-11-09 13:49:40 -05:00

Merge pull request #578 from redbar0n/master

Fix bug where RestClient would warn even if header was set correctly according to payload
This commit is contained in:
Andy Brody 2017-04-09 19:12:47 -04:00 committed by GitHub
commit 15906cc967
2 changed files with 8 additions and 1 deletions

View file

@ -373,7 +373,7 @@ module RestClient
# x-www-form-urlencoded but a Content-Type application/json was
# also supplied by the user.
payload_headers.each_pair do |key, val|
if headers.include?(key)
if headers.include?(key) && headers[key] != val
warn("warning: Overriding #{key.inspect} header " +
"#{headers.fetch(key).inspect} with #{val.inspect} " +
"due to payload")

View file

@ -280,6 +280,13 @@ describe RestClient::Request, :include_helpers do
}).to match(/warning: Overriding "Content-Length" header/i)
end
it "does not warn when overriding user header with header derived from payload if those header values were identical" do
expect(fake_stderr {
RestClient::Request.new(method: :post, url: 'example.com',
payload: {'foo' => '123456'}, headers: { 'Content-Type' => 'application/x-www-form-urlencoded' })
}).not_to match(/warning: Overriding "Content-Type" header/i)
end
it 'does not warn for a normal looking payload' do
expect(fake_stderr {
RestClient::Request.new(method: :post, url: 'example.com', payload: 'payload')