Created
June 13, 2012 01:11
-
-
Save shigeki/2921169 to your computer and use it in GitHub Desktop.
superagentをプロキシ対応するパッチ(SSL対応:要 tunnel モジュール) original from https://gist.github.com/2914780
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- 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