The HTTP response is a WritableStream
. When the stream closes, a finish event is emitted. Thus listening to it does the trick:
res.on('finish', function() { console.log(res._headers);});
Much more flexible. Can be put in a middleware or a resource handler.