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

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

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

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.