https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/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... Thanks. Mike -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
I''ve uploaded a diff to the ticket with a fix. https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5038-activeresource-not-handling-updates-correctly#ticket-5038-2 Could someone take a look? Thanks. Mike On Jul 2, 3:48 pm, Mike <mike.ab...@gmail.com> wrote:> https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5... > > 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... > > Thanks. > > Mike-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
taryn
2010-Jul-27 16:33 UTC
Re: Ticket #5038 ActiveResource not handling updates correctly
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 On Jul 2, 11:48 pm, Mike <mike.ab...@gmail.com> wrote:> https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5... > > 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... > > Thanks. > > Mike-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
taryn
2010-Jul-27 16:37 UTC
Re: Ticket #5038 ActiveResource not handling updates correctly
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 :) Cheers, Taryn On Jul 7, 10:30 pm, Mike <mike.ab...@gmail.com> wrote:> I''ve uploaded a diff to the ticket with a fix. > > https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5... > > Could someone take a look? > > Thanks. > > Mike > > On Jul 2, 3:48 pm, Mike <mike.ab...@gmail.com> wrote: > > >https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5... > > > 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... > > > Thanks. > > > Mike-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.