I have form with file upload. The files to be uploaded actually are pictures and videos, so they can be quite big. I have logic which based on headers and first 1KB can determine if the rest will be processed or immediately rejected. In the later case I'd like to redirect client to error page without having to wait for upload to finish.
The case is, that just sending response before POST is complete doesn't seem to work. The redirect gets ignored and if I close connection, browser complains with "Connection reset by peer" error.
So the question is: is it even possible to do that in pure HTTP (without JavaScript on client-side), and if so, how?
Have a look at django ticket #10850 - "Impossible to stop a large file upload mid-stream". Doesn't solve the problem, but at least it should help you understand it.
Checkout the uploadprogress examples.
The HTTP/1.1 protocol does allow for this, just in a really bizarre and messed up way. You need to apply the following 3 step proceedure:
This SHOULD work because as outlined below the client is expected to retry a connection at least once after being cut off unexpectedly. On the retry attempt(s) it is expected to only send the headers, then wait and watch for an error response and abort sending the body if it gets one.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html
Gotchas: