-
Notifications
You must be signed in to change notification settings - Fork 2k
allow us to dump the request and response content #660
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
Conversation
allow us to dump the request and response content with req.data and res.data on the proxy's event 'end'.
@wangzheng422 why is this useful for your use case? This could result in huge performance problems |
Never mind the use case. I for example would like to be able to rewrite proxyRes as I see fit. Couldn't we introduce some hook which could do the following:
This could for example return a custom stream that would wrap around original proxyRes. What do you think? |
@RushPL yea this is the reason I have an issue with this api as there is no good way to hook into the streams themselves with any kind of transform. Its something I've been thinking about but haven't found the right way to do yet. |
Well, wouldn't that be a custom EventEmitter with a couple of events handled right? I am sure this can be easily done. (perhaps tricky to get all edge cases right) |
@RushPL we can pass in two different transform streams in some manner. There may be a better api then just adding them to the options object. But yea its doable its just not as clean as I'd like it. |
allow us to dump the request content with req.data and res.data, after set the option's dump flag to true.
@jcrugzz I want to analyze the http traffic goes through the proxy, especially the POST case. Now I add a dump flag into the option, which will not turn on the dump function in normal case. |
@wangzheng422 i still dont like this. This should be done with an optional stream that you can pass so we arent adding an arbitrary property to the request and you can do with the data what you want. For what you want to do, you would pass in something like this. // Hypothetical untested code
var httpProxy = require('http-proxy');
var Transform = require('stream').Transform;
var beforeProxy = dataAttacher();
var afterProxy = dataAttacher();
beforeProxy.on('finish', function () {
console.log(beforeProxy.datas);
}):
afterProxy.on('finish', function () {
console.log(afterProxy.datas);
});
// pseduo api
var proxy = httpProxy.createProxy({
before: beforeProxy,
after: afterProxy
});
function dataAttacher () {
var transform = new Transform();
transform.datas = '';
// Just do a simple pass through but attach the data to the object
transform._transform = function (data, enc, callback) {
transform.datas += data;
callback(null, data);
};
return transform;
} Now this is just speculative but this is the way that we would make this type of functionality work. This allows custom transformations of any type on the data which should be allowed. @RushPL this would satisfy your requirements correct? |
allow us to dump the request and response content with req.data and res.data on the proxy's event 'end'.