-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A request within a request callback does not pipe back to server response #410
Comments
The following code only works outside the parent request. proxy = requester({ url: 'http://www.srcnix.com', method: 'GET' }); request.pipe(proxy); proxy.pipe(response); |
take the pipe out of the callback and use the returned stream from request, not the callback response. |
Sorry, I don't follow. Such as the following? var server = httpProxy.createServer(function(request, response) { requester({url: 'http://www.facebook.com'}, function(error, body, resp) { console.log(body); proxy = requester({ url: 'http://www.srcnix.com', method: 'GET' }); }); request.pipe(proxy); proxy.pipe(response); }); If so (And bare with me, as I'm new to nodejs), sure that wouldn't work due to the asynchronous manner of node? Not to mention proxy won't be available as out of scope... |
var server = httpProxy.createServer(function(request, response) {
requester({url: 'http://www.facebook.com'}, function(error, body, resp) {
console.log(body);
});
var proxy = requester({
url: 'http://www.srcnix.com',
method: 'GET'
});
request.pipe(proxy);
proxy.pipe(response);
}); |
Thanks for the update. The issue that is arising is the need to perform the first request before the latter, as data from the first request is required in the latter. |
ok, here's the issue, you're trying to pipe the incoming request to the last one after it's already ended. since aren't passing the request body you can fix this pretty simply. var server = httpProxy.createServer(function(request, response) {
requester({url: 'http://www.facebook.com'}, function(error, body, resp) {
console.log(body);
proxy = requester({
url: 'http://www.srcnix.com',
method: 'GET'
});
request.pipe(proxy);
proxy.pipe(response);
process.nextTick(function () { proxy.end() })
});
}); |
Any thoughts as to why having a request within a request callback will not pipe the request response back to the server.
The text was updated successfully, but these errors were encountered: