Frederick Cheung
2007-Jul-06 10:29 UTC
Receiving a request whose body ends will a null byte
Hi, I''ve been working on a problem we''ve been having with our app. In essence we have a controller that receives a blob of binary data (as a raw post) and processes it (this data happens to be a marshaled ruby object but that''s not relevant here). The problem was that occasionally the last byte of the post body was going missing. I tracked it down to the following method in action_controller/cgi_ext/ raw_post_data_fix: def read_body(content_length) stdinput.binmode if stdinput.respond_to?(:binmode) content = stdinput.read(content_length) || '''' # Fix for Safari Ajax postings that always append \000 content.chop! if content[-1] == 0 content.gsub!(/&_=$/, '''') env_table[''RAW_POST_DATA''] = content.freeze end I don''t know the history behind the truncation of the last byte if it is nil, but surely there has to be a better way to do this? Fred
Matthew Palmer
2007-Jul-06 11:29 UTC
Re: Receiving a request whose body ends will a null byte
On Fri, Jul 06, 2007 at 11:29:40AM +0100, Frederick Cheung wrote:> occasionally the last byte of the post body was going missing. I > tracked it down to the following method in action_controller/cgi_ext/ > raw_post_data_fix: > > def read_body(content_length) > stdinput.binmode if stdinput.respond_to?(:binmode) > content = stdinput.read(content_length) || '''' > # Fix for Safari Ajax postings that always append \000 > content.chop! if content[-1] == 0 > content.gsub!(/&_=$/, '''') > env_table[''RAW_POST_DATA''] = content.freeze > end > > I don''t know the history behind the truncation of the last byte if > it is nil, but surely there has to be a better way to do this?The comment at least gives a bit of context -- that Safari is broken, and this is a workaround for it. I''ve done a bit of sleuthing, though, and I can''t find this code in Edge. It is present in 1.2.3, but it''s since been removed by the look of it. Bug #918 is related to this code a bit, but isn''t the cause of it''s original inclusion. Since the entire raw_post_data_fix.rb file is gone, I''d say that a fair amount of refactoring has gone into that part of the code since the release of 1.2.3. I suspect that going to Edge might be easier than trying to retrofit whatever improved fix has been made. - Matt -- "The day when Hurd is so common that we want to emulate its braindamages is not going to be in my life-time, I suspect." -- Linus Torvalds --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Jul-06 13:49 UTC
Re: Receiving a request whose body ends will a null byte
On 6 Jul 2007, at 12:29, Matthew Palmer wrote:> > On Fri, Jul 06, 2007 at 11:29:40AM +0100, Frederick Cheung wrote: >> occasionally the last byte of the post body was going missing. I >> tracked it down to the following method in action_controller/cgi_ext/ >> raw_post_data_fix: >> >> def read_body(content_length) >> stdinput.binmode if stdinput.respond_to?(:binmode) >> content = stdinput.read(content_length) || '''' >> # Fix for Safari Ajax postings that always append \000 >> content.chop! if content[-1] == 0 >> content.gsub!(/&_=$/, '''') >> env_table[''RAW_POST_DATA''] = content.freeze >> end >> >> I don''t know the history behind the truncation of the last byte if >> it is nil, but surely there has to be a better way to do this? > > The comment at least gives a bit of context -- that Safari is > broken, and > this is a workaround for it. > > I''ve done a bit of sleuthing, though, and I can''t find this code in > Edge. It > is present in 1.2.3, but it''s since been removed by the look of > it. Bug > #918 is related to this code a bit, but isn''t the cause of it''s > original > inclusion. Since the entire raw_post_data_fix.rb file is gone, I''d > say that > a fair amount of refactoring has gone into that part of the code > since the > release of 1.2.3. I suspect that going to Edge might be easier > than trying > to retrofit whatever improved fix has been made. >I can''t see any trace of it in edge either (or even a comment explaining a similar fix). A cursory inspection with tcpdump and a current version of Safari suggests it is no longer a problem (According to the changelog the original fix dates back to 2005) and so perhaps this was just removed because affected versions of Safari are effectively dead? Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Michael Koziarski
2007-Jul-07 02:14 UTC
Re: Receiving a request whose body ends will a null byte
> I can''t see any trace of it in edge either (or even a comment > explaining a similar fix). > A cursory inspection with tcpdump and a current version of Safari > suggests it is no longer a problem (According to the changelog the > original fix dates back to 2005) and so perhaps this was just removed > because affected versions of Safari are effectively dead?I''ve yet to see strange bugs on any of my ajax-using-edge-apps, so perhaps it''s unneeded going forward. -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---