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:
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
env_table['RAW_POST_DATA'] = content.freeze
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?