Skip to content

Commit 13c8112

Browse files
Merge jonasmalacofilho#14: add proxy support through the http_proxy environment variable
From icedream2linxi/pr/support-proxy Closes jonasmalacofilho#4
2 parents 371df9b + d7ea7f0 commit 13c8112

File tree

4 files changed

+107
-28
lines changed

4 files changed

+107
-28
lines changed

bin/git-cache-http-server.js

+77-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"src": "src"
1212
},
1313
"dependencies": {
14-
"docopt": "^0.6.2"
14+
"docopt": "^0.6.2",
15+
"http-proxy-agent": "^2.1.0"
1516
},
1617
"repository": {
1718
"type": "git",

src/HttpsProxyAgent.hx

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import js.node.https.Agent;
2+
3+
@:jsRequire('http-proxy-agent')
4+
extern class HttpsProxyAgent extends js.node.https.Agent {
5+
function new(proxy:String);
6+
}

src/Main.hx

+22-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,19 @@ class Main {
5656
static function authenticate(params, infos, callback)
5757
{
5858
trace('INFO: authenticating on the upstream repo $infos');
59-
var req = Https.request('https://${params.repo}/info/refs?service=${params.service}', callback);
59+
var req:ClientRequest;
60+
if (proxyAgent == null) {
61+
req = Https.request('https://${params.repo}/info/refs?service=${params.service}', callback);
62+
}
63+
else {
64+
var opts:Https.HttpsRequestOptions = {};
65+
opts.protocol = "https:";
66+
opts.host = params.repo;
67+
opts.path = '/info/refs?service=${params.service}';
68+
opts.agent = proxyAgent;
69+
req = Https.request(opts, callback);
70+
}
71+
6072
req.setHeader("User-Agent", "git/");
6173
if (params.auth != null)
6274
req.setHeader("Authorization", params.auth.authorization);
@@ -194,6 +206,7 @@ class Main {
194206
static var updatePromises = new Map<String, Promise<Dynamic>>();
195207
static var cacheDir = "/tmp/var/cache/git/";
196208
static var listenPort = 8080;
209+
static var proxyAgent = null;
197210
static var usage = "
198211
A caching Git HTTP server.
199212
@@ -219,6 +232,14 @@ Options:
219232

220233
trace('INFO: cache directory: $cacheDir');
221234
trace('INFO: listening to port: $listenPort');
235+
236+
var env = Sys.environment();
237+
var proxyUrl = env["http_proxy"];
238+
if (proxyUrl == null)
239+
proxyUrl = env["HTTP_PROXY"];
240+
if (proxyUrl != null)
241+
proxyAgent = new HttpsProxyAgent(proxyUrl);
242+
222243
var server = Http.createServer(handleRequest);
223244
server.setTimeout(120*60*1000); // 120 * 60 seconds * 1000 msecs
224245
server.listen(listenPort);

0 commit comments

Comments
 (0)