gaxios icon indicating copy to clipboard operation
gaxios copied to clipboard

Support proxy option instead of HTTP_PROXY env variable

Open vamcc opened this issue 2 years ago • 3 comments

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 avatar Jan 10 '23 10:01 vamcc

@vamcc this library should be supporting NO_PROXY, could you provide a minimal example that is failing for you?

bcoe avatar Jan 11 '23 17:01 bcoe

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

vamcc avatar Jan 13 '23 09:01 vamcc

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!

drmrbrewer avatar Apr 18 '23 11:04 drmrbrewer

Resolving shortly via:

  • https://github.com/googleapis/gaxios/pull/614

danielbankhead avatar Apr 06 '24 00:04 danielbankhead