TooTallNate / node-proxy-agent

Maps proxy protocols to `http.Agent` implementations
285 stars 69 forks source link

Make cache key to be customizable #29

Closed sendyhalim closed 1 year ago

sendyhalim commented 6 years ago

This pull request will make http agent cache key to be customizable, sometimes you don't want to reuse proxy agent. A good example of this would be if I'm sending dynamic http header for proxy (example using superagent-proxy)

const superagent = require('superagent');
require('superagent-proxy')(superagent);

superagent
  .get(someUrl)
  .proxy({
    ...urlUtil.parse(<proxy url>),
    headers: {
      'session-id': <random value>
    }
  });

The above example wouldn't work, session-id will stay the same because proxy agent uses proxy uri as the cache key. By adding proxyAgentCacheKey options, we can override the cache key.

superagent
  .get(someUrl)
  .proxy({
    ...urlUtil.parse(<proxy url>),
    proxyAgentCacheKey: <random value>
    headers: {
      'session-id': <random value>
    }
  });
sendyhalim commented 6 years ago

Wooops, I'll update the PR to add and fix test cases

TooTallNate commented 1 year ago

This code in this repository has been moved to the proxy-agents monorepo, so I am closing this pull request. If you feel that this change is still necessary as of the latest release, feel free to open a new pull request over there.