4 ms·
Think of it the other way too: it allows the HTTP server to start writing the file to disk without having to completely load the file into memory.
by stingraycharles 16y ago
Think of it the other way too: it allows the HTTP server to start writing the file to disk without having to completely load the file into memory.
- felixge2 16y agoYou could still do that if the length was pre-announced, or am I missing something?
- stingraycharles 16y agoEhrm, yes, you're correct, I wasn't fully awake yet. I apologize.
- irrelative 16y agoYeah, you could -- I wonder what would happen if the client gets it wrong or is deliberately dishonest? Not trusting the client is a big part of writing an open server and this seems like you would have to trust the client in a big way.
- felixge2 16y agoWell, it's not a big problem - you should have a timeout on incoming connections, and node is pretty well-suited for having lots of "hanging" connections (I ran some test with 56k active connections). If a connection is closed, either by a timeout, or EOF, you simply check if the promised content length matches the count of received bytes - if not you should probably discard the whole thing (unless you're specifically supporting broken clients).