This project is archived and is in readonly mode.
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
-
Gabe da Silveira August 9th, 2009 @ 06:21 AM
- Tag changed from activeresource, bugmash, patch to activeresource, bugmash, patch, verified
verified both patches apply cleanly, and test fails without the fix
+1 on the approach of sending the Accept header. Even though the body is not sent, the server still needs to know what was requested.
-
Elise Huard August 9th, 2009 @ 11:32 AM
verified both patches, the tests fail without the fix, and code is nice and clean.
+1 makes sense. -
Elad Meidar August 9th, 2009 @ 04:01 PM
+1 makes sense, both patches apply here and tests pass with the patches.
-
Repository August 9th, 2009 @ 10:26 PM
- State changed from new to resolved
(from [1fc1986d6deacd71ec4bea2287d9cfed6123b898]) Make ActiveResource#exists? work [#3020 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com
http://github.com/rails/rails/commit/1fc1986d6deacd71ec4bea2287d9cf... -
Repository August 9th, 2009 @ 10:26 PM
(from [323f58f19f052d77e972b94767ab133d58fdcd90]) Make ActiveResource#exists? work [#3020 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com
http://github.com/rails/rails/commit/323f58f19f052d77e972b94767ab13... -
CancelProfileIsBroken August 9th, 2009 @ 10:47 PM
- Tag changed from activeresource, bugmash, patch, verified to activeresource, patch, verified
-
Elliot Winkler August 9th, 2009 @ 11:34 PM
This is actually the exact same problem I posted way back in #1223, so I think that one can be closed.
-
Jatinder Singh August 9th, 2009 @ 11:39 PM
I should have been more proactive in looking for similar tickets. sorry about stealing it from you Elliot.
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
Attachments
Tags
Referenced by
- 3020 ActiveResource#exists? does not work at all (from [1fc1986d6deacd71ec4bea2287d9cfed6123b898]) Make Ac...
- 3020 ActiveResource#exists? does not work at all (from [323f58f19f052d77e972b94767ab133d58fdcd90]) Make Ac...