title: Django/apache handle incomplete/cancelled http requests
body: <p>When django is deployed on apache with mod_wsgi. It seems to handle incomplete or cancelled requests in a very odd way.</p>
  
  <p>If the client cancels the request, the cancelled request is not cancelled on django, for example, if you are uploading a big file, obviously the body of the request will be actually streamed, so while django is reading the body, and the client cancels the request, it is still processed (just incomplete) and the actual request cancel action is never noticed.</p>
  
  <p>This is one log example from apache, when a request is cancelled.
  [Fri May 01 22:05:51.055968 2015] [:error] [pid 31609] (70008)Partial results are valid but processing is incomplete: [client 172.31.43.91:3645] mod_wsgi (pid=31609): Unable to get bucket brigade for request.</p>
  
  <p>Then on django code, the actual POST dictionary is never built (because the request is incomplete, yet it arrives to django and is processed as if it had data), and so django will then fail when trying to get data (and return missing XX field errors, or what ever the logic does to handle them)</p>
  
  <p>Finally, when django tries to write back the response, it will obviously fail as well as the client already closed the connection.</p>
  
  <p>This scenario, happens very often on a request that is used as a REST service endpoint for a mobile app. The mobile app uploads large files and so the request is cancelled on app suspend/close, yet the server always seems to get the partial request.</p>
  
  <p>The complete log when this happens would look something like this:</p>
  
  <p>[Fri May 01 22:05:51.055968 2015] [:error] [pid 31609] (70008)Partial results are valid but processing is incomplete: [client 172.31.43.91:3645] mod_wsgi (pid=31609): Unable to get bucket brigade for request.</p>
  
  <p>[Fri May 01 22:05:51.062690 2015] [:error] [pid 10580] some error message related to missing data here</p>
  
  <p>[Fri May 01 22:05:51.068790 2015] [:error] [pid 10580] [remote 172.31.43.91:0] mod_wsgi (pid=10580): Exception occurred processing WSGI script 'some-path/wsgi.py'.</p>
  
  <p>[Fri May 01 22:05:51.068827 2015] [:error] [pid 10580] [remote 172.31.43.91:0] IOError: failed to write data</p>
  
  <p>Now the final question is, is there a way to detect this kind of incomplete request and handle it accordingly, rather than just failing later with missing required data?</p>