This project is archived and is in readonly mode.

#3020 ✓resolved
Jatinder Singh

ActiveResource#exists? does not work at all

Reported by Jatinder Singh | August 9th, 2009 @ 05:27 AM

ActiveResource#exists? which sends a HEAD request to find whether a resource exists, fails to work under all conditions.

Here is the problem: For HEAD requests, {nil => "application/xml"} is sent as header information to Net:HTTP, and the latter complains. This wasn't probably detected so far, as tests do not fail due to http mock.

Following is the relevant code from ActiveResource::Connection

    HTTP_FORMAT_HEADER_NAMES = {  :get => 'Accept',
      :put => 'Content-Type',
      :post => 'Content-Type',
      :delete => 'Accept'
    }

    def head(path, headers = {})
      request(:head, path, build_request_headers(headers))
    end

    def build_request_headers(headers, http_method=nil)
      authorization_header.update(default_header).update(http_format_header(http_method)).update(headers)
    end

    def http_format_header(http_method)
      {HTTP_FORMAT_HEADER_NAMES[http_method] => format.mime_type}
    end

This is fixed by making sure that there is a key for head in HTTP_FORMAT_HEADER_NAMES. I've attached a patch for Rails 2.3-stable(patch for edge Rails coming next..)

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Referenced by

Pages