HTTP request stream not readable outside of request handler
- by Jason Young
I'm writing a fairly complicated multi-node proxy, and at one point I need to handle an HTTP request, but read from that request outside of the "http.Server" callback (I need to read from the request data and line it up with a different response at a different time). The problem is, the stream is no longer readable. Below is some simple code to reproduce the issue. Is this normal, or a bug?
function startServer() {
http.Server(function (req, res) {
req.pause();
checkRequestReadable(req);
setTimeout(function() {
checkRequestReadable(req);
}, 1000);
setTimeout(function() {
res.end();
}, 1100);
}).listen(1337);
console.log('Server running on port 1337');
}
function checkRequestReadable(req) {
//The request is not readable here!
console.log('Request writable? ' + req.readable);
}
startServer();