title: Handling HTTP chunked encoding with django
body: <p>I have a problem handeling http chunked transfer encoding.</p>
  
  <p>I'm using: </p>
  
  <ul>
  <li>apache.</li>
  <li>mod_wsgi plugin.  </li>
  <li>django.</li>
  </ul>
  
  <p>django, is only capable of handling reqular http request with content-length header field, but when it comes to handling TE (Transfer-Encoding), chunked or gzip, it returns an empty result.</p>
  
  <p>I'm thinking of 2 approaches:</p>
  
  <ol>
  <li>Making some modification to django.wsgi python file</li>
  <li>Add some middleware python file to django, to intercept any chunked http request,convert it to requelar http request with content-length header field, then, pass it to django, where it can handle it nicely.</li>
  </ol>
  
  <p>Anybody can help with any of the above 2 options (more options are most welcome of course) </p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p>This is an extention to my question after Graham's first anwer:</p>
  
  <p>First of all, thanks for your quick response. The client being used is Axis, which is a part of another company's system communicating with ours. I had <code>WSGIChunkedRequest On</code> set, I also made some modifications to my wsgi wrapper like this: </p>
  
  <p><code>def application(environ, start_response):</code>
  <i> </p>
  
  <pre><code>    if environ.get("mod_wsgi.input_chunked") == "1":
          stream = environ["wsgi.input"]
          print stream
          print 'type: ', type(stream)
          length = 0
          for byte in stream:
              length+=1
          #print length    
          environ["CONTENT_LENGTH"] = len(stream.read(length))
  
      django_application = get_wsgi_application()
      return django_application(environ, start_response)
  </code></pre>
  
  <p></i></p>
  
  <p>but it gives me those errors (extracted from apache's error.log file):</p>
  
  <pre><code>[Sat Aug 25 17:26:07 2012] [error] &lt;mod_wsgi.Input object at 0xb6c35390&gt;
  [Sat Aug 25 17:26:07 2012] [error] type:  &lt;type 'mod_wsgi.Input'&gt;
  [Sat Aug 25 17:26:08 2012] [error] [client xxxxxxxxxxxxx] mod_wsgi (pid=27210): Exception occurred processing WSGI script '/..../wsgi.py'.
  [Sat Aug 25 17:26:08 2012] [error] [client xxxxxxxxxxxxx] Traceback (most recent call last):
  [Sat Aug 25 17:26:08 2012] [error] [client xxxxxxxxxxxxx]   File "/..../wsgi.py", line 57, in application
  [Sat Aug 25 17:26:08 2012] [error] [client xxxxxxxxxxxxx]     for byte in stream:
  [Sat Aug 25 17:26:08 2012] [error] [client xxxxxxxxxxxxx] IOError: request data read error
  </code></pre>
  
  <p>What Am I doing wrong?!</p>