-
Notifications
You must be signed in to change notification settings - Fork 2k
res.on('end', callback) not working #214
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
Comments
You should listen to request's end event: var httpProxy = require('http-proxy');
httpProxy.createServer(function (req, res, proxy) {
var buffer = httpProxy.buffer(req);
req.on('end', function() {
console.log("The request was proxied");
});
proxy.proxyRequest(req, res, {
host: '127.0.0.1',
port: 80,
buffer: buffer
});
}).listen(8080); |
But if the |
Yeah, I see what you mean. The request would have been proxied, but the response back might not necessarily be done.
|
http://nodejs.org/api/http.html#http_class_http_serverresponse Apparently However - the proxy should emit an end event. I'm still not sure why this isn't happening. |
I've already pointed out this issue in #157 |
Cool, thanks for linking that! I'll try to fix this right now. |
Hey, I made a pull request for this here: #216 You'll probably want to use the following code to do this, otherwise you'll run into the case I mentioned in that pull request: var http = require('http'),
httpProxy = require('http-proxy');
var proxy = new httpProxy.RoutingProxy();
proxy.on('end', function() {
console.log('proxied');
})
http.createServer(function (req, res) {
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 8080
});
}).listen(8000); Note that this will only work after the pull request is merged! |
Check the pull request for an alternative way to do it. It might work better for you. Documentation was added in the pull request as well for this case. |
Thanks, anyways I think this should be pushed in master. |
@thefosk You should say that in the pull request =D |
I think that the following code fixes it in the current non-patched version. Basically I've monkey patched the var httpProxy = require('http-proxy');
httpProxy.createServer(function (req, res, proxy) {
var buffer = httpProxy.buffer(req);
middleware(res, function() {
console.log("The request was proxied");
});
proxy.proxyRequest(req, res, {
host: 'google.com',
port: 80,
buffer: buffer
});
}).listen(9091);
function middleware(res, callback) {
var _end = res.end;
res.end = function(data) {
_end.call(res, data);
if (callback) callback();
}
} This should be reliable as well. Thoughts? |
Yeah, sure, if you're fine with your code like that. I mean, you're patching the |
My code:
The text was updated successfully, but these errors were encountered: