Change proxy in ProxyAgent instance
bisubus opened this issue · 1 comments
ProxyAgent already handles other agents' instances and is able to instantiate them after its own construction. Can we make a proxy switchable in ProxyAgent instance?
So an instance could created, passed as agent
to request library of choice and still able to change proxy URI on the fly.
In its most simple form it may be like that.
class SwitchableProxyAgent extends ProxyAgent {
get proxyUri() {
return this._uri;
}
set proxyUri(uri) {
this._uri = uri;
this.proxy = url.parse(uri);
}
}
A few problems persist with extending existing ProxyAgent
- original
opts
object isn't reusable after construction, there's no way to tell fromthis.proxy
if the option is there on purpose (likeopts.secureEndpoint
) or it was parsed from URI - custom proxy types are private and cannot be reached from outside the constructor (incidentally, they were available once)
- the only way to switch proxy type (
proxyFn
) after instantiation is to recreate the whole constructor logic
This could be fixed by exposing this.opts
and this.proxies
and moving almost all constructor code to something like this.setProxyUri
(proxyUri
accessors would be ok, too). BTW, this may improve unit-testability.
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 issue still exists as of the latest release, feel free to open a new issue over there.