1

We have the following example in node.js

var http = require('http'); http.createServer(function(request, response) { var proxy = http.createClient(8083, '127.0.0.1') var proxy_request = proxy.request(request.method, request.url, request.headers); proxy_request.on('response', function (proxy_response) { proxy_response.pipe(response); response.writeHead(proxy_response.statusCode, proxy_response.headers); }); setTimeout(function(){ request.pipe(proxy_request); },3000); }).listen(8081, '127.0.0.1'); 

The example listen to a request in 127.0.0.1:8081 and sends it to a dummy server (always return 200 OK status code) in 127.0.0.1:8083.

The problem is in the pipe among the input stream (readable) and output stream (writable) when we have a async module before (in this case the setTimeOut timing). The pipe doesn't work and nothing is sent to dummy server in 8083 port.

Maybe, when we have a async call (in this case the setTimeOut) before the pipe call, the inputstream change to a state "not readable", and after the async call the pipe doesn't send anything.

This is just an example...we test it with more async modules from node.js community with the same result (ldapjs, etc)...

We try to fix it with: - request.readable =true; //before pipe call - request.pipe(proxy_request, {end : false}); with the same result (the pipe doesn't work).

Can anybody help us?

2
  • pipes definitely work in node. I am using them in several places in my own project. There are good examples of how to use in the node docs on streams, and in the request module docs Commented Jun 21, 2012 at 13:33
  • You and I definitely seem to have the same problem: stackoverflow.com/questions/11182725/… Commented Jun 25, 2012 at 2:52

1 Answer 1

0

I believe this works as of 0.8.0. I didn't try in 0.6.11+

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.