1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Convert symbol header keys when default headers are empty - Fixes #629 (#630)

This commit is contained in:
Eric Haynes 2018-12-06 12:26:42 -05:00 committed by Nikita Misharin
parent 67d00d1d05
commit e59472b5ba
2 changed files with 15 additions and 8 deletions

View file

@ -574,8 +574,11 @@ module HTTParty
end
def process_headers(options)
if options[:headers] && headers.any?
if options[:headers]
if headers.any?
options[:headers] = headers.merge(options[:headers])
end
options[:headers] = Utils.stringify_keys(process_dynamic_headers(options[:headers]))
end
end

View file

@ -1,3 +1,5 @@
require_relative 'spec_helper'
RSpec.describe HTTParty do
before(:each) do
@klass = Class.new
@ -192,7 +194,7 @@ RSpec.describe HTTParty do
end
it 'adds optional cookies to the optional headers' do
expect_headers(baz: 'spax', 'cookie' => 'type=snickerdoodle')
expect_headers('baz' => 'spax', 'cookie' => 'type=snickerdoodle')
@klass.get('', cookies: {type: 'snickerdoodle'}, headers: {baz: 'spax'})
end
end
@ -215,12 +217,14 @@ RSpec.describe HTTParty do
end
context 'when headers passed as symbols' do
let(:headers) { { 'foo' => 'application/json', 'bar' => 'example' } }
it 'converts them to string' do
expect(HTTParty::Request).to receive(:new)
.with(anything, anything, hash_including({ headers: headers }))
.and_return(double("mock response", perform: nil))
expect_headers('foo' => 'application/json', 'bar' => 'example')
headers = { foo: 'application/json', bar: 'example' }
@klass.post('http://example.com', headers: headers)
end
it 'converts default headers to string' do
expect_headers('foo' => 'application/json', 'bar' => 'example')
@klass.headers(foo: 'application/json')
@klass.post('http://example.com', headers: { bar: 'example' })