From b9d76c7fc6983bec2e9352fce3ec905edc9d4e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beausoleil?= Date: Wed, 12 Aug 2009 14:06:50 -0400 Subject: [PATCH] Correctly send the payload's headers to the Net::HTTP::Request subclass. --- lib/restclient/request.rb | 7 +++++-- spec/request_spec.rb | 14 +++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/restclient/request.rb b/lib/restclient/request.rb index 92a9adf..508bc0f 100644 --- a/lib/restclient/request.rb +++ b/lib/restclient/request.rb @@ -54,10 +54,13 @@ module RestClient user_headers[:cookie] = @cookies.map {|key, val| "#{key.to_s}=#{val}" }.join('; ') end - default_headers.merge(user_headers).inject({}) do |final, (key, value)| + headers = default_headers.merge(user_headers).inject({}) do |final, (key, value)| final[key.to_s.gsub(/_/, '-').capitalize] = value.to_s - final + final end + + headers.merge!(@payload.headers) if @payload + headers end def net_http_class diff --git a/spec/request_spec.rb b/spec/request_spec.rb index b6ec704..00b799f 100644 --- a/spec/request_spec.rb +++ b/spec/request_spec.rb @@ -93,17 +93,25 @@ describe RestClient::Request do it "merges user headers with the default headers" do @request.should_receive(:default_headers).and_return({ '1' => '2' }) - @request.make_headers('3' => '4').should == { '1' => '2', '3' => '4' } + headers = @request.make_headers('3' => '4') + headers.should have_key('1') + headers['1'].should == '2' + headers.should have_key('3') + headers['3'].should == '4' end it "prefers the user header when the same header exists in the defaults" do @request.should_receive(:default_headers).and_return({ '1' => '2' }) - @request.make_headers('1' => '3').should == { '1' => '3' } + headers = @request.make_headers('1' => '3') + headers.should have_key('1') + headers['1'].should == '3' end it "converts header symbols from :content_type to 'Content-type'" do @request.should_receive(:default_headers).and_return({}) - @request.make_headers(:content_type => 'abc').should == { 'Content-type' => 'abc' } + headers = @request.make_headers(:content_type => 'abc') + headers.should have_key('Content-type') + headers['Content-type'].should == 'abc' end it "converts header values to strings" do