Ticket #5038 ActiveResource not handling updates correctly


I just added this ticket. I'm writing a Sinatra API to be consumed by Rails and I've run into an issue where the ActiveResource documentation specifies that on update you should return an HTTP 204 status with no body. The problem is that Rack doesn't allow you to set the Content-Length header of HTTP 204 responses.

The workaround seems to be to return a 200 response with a zero length Content-Length header and body, but that's not what the docs say.

The fix is simple and laid out in the ticket, but here it is.

def load_attributes_from_response(response)   if !response['Conent-Length'].blank? && response['Content-Length'] ! = "0" && response.body.strip.size > 0     load(self.class.format.decode(response.body))   end end

This brings up an issue with the HttpMock class included with ActiveRecord. It defaults to specifying a Content-Type header of 0 for all requests that don't have a body. Assuming Rack has the HTTP rules correct (204 shouldn't have that header), then the HttpMock class is also broken.

I've just started cloning the repository to create a patch, but I'm not sure how I should update the tests. Any pointers would be great. Otherwise if someone wants to throw in the fix for me...



I've uploaded a diff to the ticket with a fix.


Could someone take a look?



Hi, just curious.. but why do you need to set the content-length header on the 204 response? according to the HTTP docs, a 204 literally means "no content to send". Perhaps I just misunderstand your requirements? Cheers, Taryn

Gah - my bad, ignore my previous email - I hadn't read the ticket.

You definitely need to make the tests work if submitting a patch - that means, if HttpMock is broken then it needs an update, based on what you've found out.

Sorry if I'm repeating the obvious :slight_smile: Cheers, Taryn