Skip to content

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

Closed
wants to merge 2 commits into from

Conversation

wangzheng422
Copy link

allow us to dump the request and response content with req.data and res.data on the proxy's event 'end'.

allow us to dump the request and response content with req.data and res.data on the proxy's event 'end'.
@jcrugzz
Copy link
Contributor

jcrugzz commented Jun 12, 2014

@wangzheng422 why is this useful for your use case? This could result in huge performance problems

@Rush
Copy link
Contributor

Rush commented Jun 12, 2014

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:

if(config.proxyResHook) {
   proxyRes = config.proxyResHook(proxyRes, req);
}

This could for example return a custom stream that would wrap around original proxyRes. What do you think?

@jcrugzz
Copy link
Contributor

jcrugzz commented Jun 12, 2014

@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.

@Rush
Copy link
Contributor

Rush commented Jun 12, 2014

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)

@jcrugzz
Copy link
Contributor

jcrugzz commented Jun 12, 2014

@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.
@wangzheng422
Copy link
Author

@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.

@jcrugzz
Copy link
Contributor

jcrugzz commented Jun 13, 2014

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants