Hi,
I am developing a mobile application (Java ME) against a Ruby on Rails
prototype server running WEBrick (same issue on Mongrel, haven’t got
around to trying with other servers yet).
My mobile application uploads data from the phone to the server via an
HTTP Post. Unavoidably, the phone uses transfer-encoding: chunked since
the post size exceeds a certain phone buffer of ~2,000 bytes.
The issue I have that when I handle this data in Rails, I use
request.raw_post. But whenever chunking is used, request.raw_post
returns 0 bytes instead of the original post.
I have tracked the issue down to the file
/actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb
in which the following code creates the RAW_POST_DATA environment
variable (Rails 1.1.16)
54: content = stdinput.read(Integer(env_table[‘CONTENT_LENGTH’])) || ‘’
However, according to HTTP protocol, Content-Length is not set when
chunked mode is used, so nothing is read into RAW_POST_DATA.
I have managed to workaround this by hacking WEBrick, but that doesn’t
work if I move to another production environment. Does anyone have a
better suggestion like
- A Web Server that does set Content-Length for the request after
reading the chunked data? - A Rails patch that fixes the above?
- A homemade patch that fixes the above?
For example, I could imagine changing the line above so that if
CONTENT_LENGTH is 0, all bytes available from stdinput are read
instead, but is there a reason not to? Could it be harmful in other
situations?
Thanks
//Dave