Open chenzx opened 8 years ago
proxy.on('proxyRes', function(proxyReq, req, res, options) {
var oldWrite = res.write,
oldEnd = res.end;
var chunks = [];
res.write = function (chunk) {
chunks.push(chunk);
oldWrite.apply(res, arguments);
};
res.end = function (chunk) {
if (chunk)
chunks.push(chunk);
// request body
var body = Buffer.concat(chunks);
oldEnd.apply(res, arguments);
};
});
I haven't thought of overriding default methods, thanks!!!
2016-01-23 15:50 GMT+08:00 John Wong notifications@github.com:
proxy.on('proxyRes', function(proxyReq, req, res, options) { var oldWrite = res.write, oldEnd = res.end;
var chunks = [];
res.write = function (chunk) { chunks.push(chunk); oldWrite.apply(res, arguments); };
res.end = function (chunk) { if (chunk) chunks.push(chunk);
// request body var body = Buffer.concat(chunks); oldEnd.apply(res, arguments);
}; });
— Reply to this email directly or view it on GitHub https://github.com/nodejitsu/node-http-proxy/issues/936#issuecomment-174157553 .
This approach worked fine for us as well. Thanks for sharing.
When i first wanted to build a local http proxy server, and cache all the images data to local disk, i searched for all the available proxy server scripts, since i like JavaScript, i preferred and tried node-http-proxy lib at first, but i found a problem:
In Node, stream objects can easily "pipe", since it's builtin method.
But i cannot easily clone/dump a stream, there is no such method. (Can i dispatch a single stream to multiple output channels?)
So i use python's httproxy, httproxy is too naive but it works after some modification.
Finally i switched to goproxy, which is really feature-complete and API-friendly.