gaxios
gaxios copied to clipboard
Support proxy option instead of HTTP_PROXY env variable
Is your feature request related to a problem? Please describe.
Using HTTP_PROXY
env variable will affect other requests which may also come from some other third-party packages. And not every package support NO_PROXY
env variable. In my scene, I just want to proxy request from googleapis which depend on gaxios and keep other requests called directly.
Describe the solution you'd like
Support proxy
variable in options instead of global env variable, so that developers can keep the proxy in control.
gaxios.request({
url: 'xxx',
proxy: 'yyy'
})
Describe alternatives you've considered
I tried to list all the third-party url and use NO_PROXY
to resolve this problem, but I failed. Not every package support NO_PROXY
Additional context
@vamcc this library should be supporting NO_PROXY
, could you provide a minimal example that is failing for you?
@vamcc this library should be supporting
NO_PROXY
, could you provide a minimal example that is failing for you?
Yes, but not every package use gaxios
as its request client. Maybe some other request clients just support 'HTTP_PROXY’ but not 'NO_PROXY'.
I found options.agent below, does it work?
{
agent: new HttpsProxyAgent(proxy),
}
Here is the source code about opts.agent
and proxy
.
I doubt is this an alternative provided for developers?😂
I agree that it would be nice to be able to specify a proxy
on a per-request level via a simple proxy: 'http://my.proxy.com'
option, rather than using a global env var as suggested here, which will apply to all requests made in that environment.
Having said that, it does indeed seem to be possible already to set a per-request proxy using agent: new HttpsProxyAgent('http://my.proxy.com')
but this requires the extra leg-work of installing the https-proxy-agent
module and importing with import HttpsProxyAgent from 'https-proxy-agent'
... not a massive deal but a proxy
option would be nicer IMHO!
Resolving shortly via:
- https://github.com/googleapis/gaxios/pull/614