Skip to content

Instantly share code, notes, and snippets.

@shigeki
Created June 13, 2012 01:11
Show Gist options
  • Save shigeki/2921169 to your computer and use it in GitHub Desktop.
Save shigeki/2921169 to your computer and use it in GitHub Desktop.
superagentをプロキシ対応するパッチ(SSL対応:要 tunnel モジュール) original from https://gist.github.com/2914780
--- node_modules/tower/node_modules/superagent/lib/node/index.js.org 2012-06-03 04:27:15.000000000 +0900
+++ node_modules/tower/node_modules/superagent/lib/node/index.js 2012-06-13 10:07:53.142584979 +0900
@@ -458,6 +458,29 @@
// initiate request
var mod = exports.protocols[url.protocol];
+ // use proxy
+ if(process.env.http_proxy) {
+ var proxy = parse(process.env.http_proxy);
+ if (url.protocol === 'http:') {
+ options.port = proxy.port;
+ options.path = this.url;
+ options.host = proxy.hostname;
+ } else if (url.protocol === 'https:') {
+ // need node-tunnel module for SSL proxy
+ // for global install use 'sudo npm install -g tunnel'
+ try {
+ options.agent = require('tunnel').httpsOverHttp({
+ proxy: {
+ host: proxy.hostname,
+ port: proxy.port
+ }
+ });
+ } catch(e) {
+ console.error(e.message);
+ }
+ }
+ }
+
// request
var req = this.req = mod.request(options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment