views:

304

answers:

1

We have a web based application in production built using django. It is deployed on nginx proxied with apache which handles the django app via WSGI. OS is Ubuntu.

In addition to the web based front-end, we recently developed a J2ME client for uploading files via mobile phone. The J2ME transfers the file with Transfer-Encoding set as "Chunked" and content length set to zero; that is the standard way for the J2ME framework and apparently it cannot be changed.

The problem is that neither nginx, nor apache allow zero content length chunked data and give back HTTP 411 error response. django also seems problematic but it can be patched easily.

Few solutions on net suggest recompiling nginx and apache but I don't want to go into that. Could there be a much simpler solution?

A: 

In my experience, J2ME switches to chunked encoding if you use OutputStream.flush(). Avoid flush, just write to the OutputStream then close it immediately. I was able to submit a POST to an Apache/Django setup with J2ME just fine. I was getting 411 errors because of using flush(). Once I removed it it worked fine. I did not set Content-Length manually, it was automatically set.

rryan
Just kidding, the chunked encoding comes back if the body is too large. I ended up using mod_proxy to buffer the chunked encodings into regular requests. http://stackoverflow.com/questions/284741/processing-chunked-encoded-http-post-requests-in-python-or-generic-cgi-under-apa
rryan
I've tried mod_proxy but on certain requests (mostly when connection is made with deviceside=True) it doesn't work and I get error in the proxy log similar to: given Content-Length did not match number of body bytes read ... End of file found: proxy: pass request body failed to x.x.x.x:8080 from y.y.y.y () ... Handler for proxy-server returned invalid result code 70014
sharjeel