From d0bae9a9e1877e210f1e593b570d8eed13baf523 Mon Sep 17 00:00:00 2001 From: Joshua Bates Date: Fri, 20 Mar 2009 23:25:36 -0700 Subject: [PATCH] Fix ActiveResource headers for head requests --- activeresource/lib/active_resource/connection.rb | 5 +++-- activeresource/test/connection_test.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index 85103b5..5e4091c 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -67,7 +67,8 @@ module ActiveResource HTTP_FORMAT_HEADER_NAMES = { :get => 'Accept', :put => 'Content-Type', :post => 'Content-Type', - :delete => 'Accept' + :delete => 'Accept', + :head => 'Content-Type' } attr_reader :site, :user, :password, :timeout @@ -137,7 +138,7 @@ module ActiveResource # Execute a HEAD request. # Used to obtain meta-information about resources, such as whether they exist and their size (via response headers). def head(path, headers = {}) - request(:head, path, build_request_headers(headers)) + request(:head, path, build_request_headers(headers, :head)) end diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb index 831fbc4..b31131c 100644 --- a/activeresource/test/connection_test.rb +++ b/activeresource/test/connection_test.rb @@ -117,6 +117,14 @@ class ConnectionTest < Test::Unit::TestCase assert_equal 200, response.code end + def test_head_content_type_header + http_mock = Net::HTTP.new('localhost') + http_mock.stubs(:request => ActiveResource::Response.new("")) + @conn.stubs(:http => http_mock) + + assert_nothing_raised { @conn.head("/people/1.xml") } + end + def test_get_with_header david = @conn.get("/people/2.xml", @header) assert_equal "David", david["name"] -- 1.6.1