Skip to content
This repository has been archived by the owner on Dec 24, 2018. It is now read-only.

issue #47 - proxy support in wget.js #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion wget.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ function wget(uri, callback) {
var options = url.parse(uri);
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']) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should define variable proto before use in this line.

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) {
Expand Down