News for hackers. Stuff that matters.
Re:The Several Million Dollar Bug by joosters on Monday June 09, 2014 @07:52AM (#7867966)
It is fine to respond early to a HTTP request, e.g. returning a permissions error when a user tries to upload a file. Beware however that some clients will go badly wrong if they don't get to send all their data.

What can happen is:

* Client starts to send HTTP request (e.g. POSTing a file). The file is large, so it will take a while to upload.

* Server spots that the user isn't allowed to upload the file and immediately returns a 4xx error of some kind.

* Server then thinks all is finished, closes connection.

* Client, still sending the file, gets an error as the write() fails. Complains about the broken connection to the user but never notices the actual HTTP response.

Many HTTP clients are written in a simple 'send my request, then (and only then) read the response'. They don't react well to getting an early error message. Often you have to work around this by not closing the connection to the client, and continuing to slurp up any further data received.

There are no comments on this comment yet.