Skip to content

Instantly share code, notes, and snippets.

@jfromaniello
Last active April 9, 2020 07:43
Show Gist options
  • Save jfromaniello/6380601 to your computer and use it in GitHub Desktop.
Save jfromaniello/6380601 to your computer and use it in GitHub Desktop.
if (!process.env.http_proxy) return;
var url = require('url');
var tunnel = require('tunnel');
var proxy = url.parse(process.env.http_proxy);
var tunnelingAgent = tunnel.httpsOverHttp({
proxy: {
host: proxy.hostname,
port: proxy.port
}
});
var https = require('https');
var oldhttpsreq = https.request;
https.request = function (options, callback) {
options.agent = tunnelingAgent;
return oldhttpsreq.call(null, options, callback);
};
var http = require('http');
var oldhttpreq = https.request;
http.request = function (options, callback) {
options.agent = tunnelingAgent;
return oldhttpreq.call(null, options, callback);
};
@adrukh
Copy link

adrukh commented Apr 2, 2017

Very helpful, thanks!
Please fix line 22 - should be var oldhttpreq = http.request;

@GabrieleRomeo
Copy link

Thanks a lot for your gist!

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