Skip to content

Sent requests via HTTP proxy #64

@jrcryer

Description

@jrcryer

It would be nice to be able to use the google-api-nodejs-client via a HTTP proxy. Request appears to support proxy configuration.

Possibly via the withOpts:

discover('youtube', 'v3').withOpts({ proxy: 'http://mylocalproxy.com' });

Activity

ryanseys

ryanseys commented on Jul 22, 2014

@ryanseys
Contributor

Fixed in 1.0.0. You can now specify additional options to the request object at the global or service level.

var google = require('googleapis');
var youtube = google.youtube({ version: 'v3', proxy: /* proxy here */ });
// .. use youtube object here

To see more information look at README#Options and more information on setting a proxy can be found here. (Our library just relays the settings to the mikeal/request object)

Juljan

Juljan commented on Jul 25, 2014

@Juljan

Seems it does not work for the auth API. I may be wrong but I think the proxy is not set in the calls to this.transporter.request in oauth2client.js.

ryanseys

ryanseys commented on Jul 25, 2014

@ryanseys
Contributor

Hi @Juljan, there's a test you can find here that will show you how to apply things like proxy to a request.

ryanseys

ryanseys commented on Jul 25, 2014

@ryanseys
Contributor

I have written an additional test here to test the scenario of setting a proxy with auth set to an oauth client. The test passed with no additional changes to the code, so you can be sure that it is working.

flo-sch

flo-sch commented on Oct 1, 2014

@flo-sch

What about HTTPS proxys ? Is there any plan to support it in the future ? Should it be reported to the "request" project issues ?

aguegu

aguegu commented on Oct 11, 2014

@aguegu

I have tried set a global proxy with

google.options({ proxy: 'http://127.0.0.1:7777' });

But as I checked my local http proxy debug log, google api nodejs client does not always go through this proxy. Sometime it does, sometime it trys to access directly (and it would not success in my scenario).

Can anyone help me test on it?

aguegu

aguegu commented on Oct 11, 2014

@aguegu

As checking request doc,

add this line before google.options({ proxy: 'http://127.0.0.1:7777' }); helps:

process.env.HTTPS_PROXY = 'http://127.0.0.1:7777';

https://github.com/mikeal/request#controlling-proxy-behaviour-using-environment-variables

vaughnmuirhead

vaughnmuirhead commented on Sep 7, 2017

@vaughnmuirhead

Yep, process.env.HTTPS_PROXY = 'http://:'; worked for me. Thanks @aguegu

mirismaili

mirismaili commented on Sep 3, 2020

@mirismaili

I tried google.options({ proxy: 'http://SOMETHING_WRONG' }). It works regularly! So it shouldn't be the correct setting.

I found the below option works as expected:

const HttpsProxyAgent = require('https-proxy-agent')
const {google} = require('googleapis')
google.options({
	agent: new HttpsProxyAgent('http://127.0.0.1:8580')
})

This crashes on invalid proxies and works on valid proxies, as expected.


Ref:
https://github.com/googleapis/google-api-nodejs-client#request-options says:

For more fine-tuned control over how your API calls are made, we provide you with the ability to specify additional options that can be applied directly to the 'gaxios' object used in this library to make network calls to the API.

And gaxios introduces itself:

An HTTP request client that provides an axios like interface over top of node-fetch

And node-fetch uses http-agent:

https://github.com/node-fetch/node-fetch#custom-agent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.triage meI really want to be triaged.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @ryanseys@jrcryer@aguegu@flo-sch@Juljan

      Issue actions

        Sent requests via HTTP proxy · Issue #64 · googleapis/google-api-nodejs-client