This repository has been archived by the owner. It is now read-only.

Inaccurate ClientResponse 'end' event documentation #4116

Closed
egirshov opened this Issue Oct 11, 2012 · 4 comments

Comments

Projects
None yet
2 participants

Another minor documentation issue, it says:

After emitted no other events will be emitted on the response.

Although I guess it means "no 'data' events will be emitted", since there is a case then a 'close' event is emitted after 'end'.

Member

bnoordhuis commented Oct 11, 2012

since there is a case then a 'close' event is emitted after 'end'.

You mean http.ClientResponse, right? The documentation is right, you're not supposed to get a 'close' event after an 'end' event. If you do, it's a bug.

Yes, I was referring to http.ClientResponse. Here is sample code:

var http = require('http');
http.createServer(function (req, res) {
    req.on('end', function () {
        res.writeHead(200);
        res.write('Bla-bla-bla');
        setTimeout(function () { res.end('Blah.'); }, 5000);
    }); 
}).listen(8000);
var request = http.request({port: 8000}, function (response) {
    setTimeout(function () {
        request.abort();
        response.once('end', function () {
            console.log('http.ClientResponse `end`');
            response.once('close', function () {
                console.log('http.ClientResponse `close` too');
            }); 
        }); 
    }, 2000);
});
request.end();

bnoordhuis added a commit to bnoordhuis/node that referenced this issue Oct 12, 2012

doc: rectify http.ClientResponse close/end events
* The 'close' event doesn't emit an error object.

* It's possible for a 'close' event to come after an 'end' event, contrary to
  what the documentation said.

Fixes #4116.
Member

bnoordhuis commented Oct 12, 2012

Right, I was wrong (as was that part of the documentation - it's documented correctly elsewhere). Can someone review c8af471?

Member

bnoordhuis commented Oct 13, 2012

Fixed in 4a23add.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.