What happens in NodeJS if I call response.end() as soon as I receive a request without supplying any data, calling response.write(), or calling response.writeHead()? I'm curious about the answer from two angles:
1) the server angle - does this essentially take something off of a backend stack or heap within nodeJS that frees up some resources? or does something entirely different happen?
2) the client perspective - If this is coming from an ajax request that doesn't expect to receive any data in response, can any problems arise?
The obvious thing to do here, is just to try it. Node.js code:
var http = require('http');
http.createServer(function (req, res) {
res.end();
}).listen(1337, '127.0.0.1');
From the server perspective it's not different to adding data / custom headers in there.
From client perspective, gives me empty response body, with headers:
Connection:keep-alive
Date:Sun, 29 Jul 2012 07:58:51 GMT
Transfer-Encoding:chunked
The difference to the hello world example is that Content-Type
header is missing and the response body is empty and that's it.
1) All resources associated with the request and response are relinquished (made available for garbage collection)
2) node sends out a response with default headers and an empty body. It's purely up to the client how to deal with that. In most cases, the client will regard the default headers as incomplete, but in the absence of a response body, there's no alternative.