From 00f9ee45ade36f4ff3a71f815096a1670f0a27c4 Mon Sep 17 00:00:00 2001 From: PyHedgehog Date: Tue, 21 Apr 2015 18:55:10 +0300 Subject: [PATCH 1/2] issue #47 - proxy support in wget.js --- wget.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/wget.js b/wget.js index fade3e4..1012f62 100644 --- a/wget.js +++ b/wget.js @@ -9,9 +9,18 @@ function wget(uri, callback) { var options = url.parse(uri); var paths = options.pathname.split('/'); var filename = paths[paths.length - 1]; + var proxy; + if(process.env[proto+'_proxy']) { + proxy = url.parse(process.env[proto+'_proxy']); + } + if(proxy) { + proxy.path = proxy.pathname = options.protocol+'//'+options.host+options.pathname; + options = proxy; + proto = options.protocol.slice(0,-1); + } console.log(filename); - var http = require(uri.indexOf('https') === 0 ? 'https' : 'http'); + var http = require(proto); var req = http.get(options, function (res) { if (res.statusCode === 302 || res.statusCode === 301) { From a319afe732c3ff22a660e9946e173ce253f55f35 Mon Sep 17 00:00:00 2001 From: Michael Dubner Date: Tue, 12 May 2015 20:19:20 +0300 Subject: [PATCH 2/2] var proto --- wget.js | 1 + 1 file changed, 1 insertion(+) diff --git a/wget.js b/wget.js index 1012f62..1830683 100644 --- a/wget.js +++ b/wget.js @@ -10,6 +10,7 @@ function wget(uri, callback) { var paths = options.pathname.split('/'); var filename = paths[paths.length - 1]; var proxy; + var proto = options.protocol.slice(0,-1); if(process.env[proto+'_proxy']) { proxy = url.parse(process.env[proto+'_proxy']); }