Following is a standard Node.js http get request. In the callback function, we listen response 'data' and 'end' event.
My question is: what if the response data event fired before the callback execution? It seems possible to me.
var request = http.get(option, function(res) {
res.setEncoding('utf8');
var data = "";
res.on('data', function(d) {
data += d
});
res.on('end', function() {
...
});
});
res is just an instance of the http.ClientResponse class that magically comes into the callback right after response headers processing and strictly before the HTTP response body.