HTTP request stream not readable outside of request handler
Posted
by
Jason Young
on Stack Overflow
See other posts from Stack Overflow
or by Jason Young
Published on 2012-06-25T02:03:09Z
Indexed on
2012/06/26
3:16 UTC
Read the original article
Hit count: 229
node.js
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();
© Stack Overflow or respective owner