Skip to content

Commit 0e3ff99

Browse files
committed
Require a proper proxy, if one is supplied
1 parent f4e8e5a commit 0e3ff99

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

lib/utils/default-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports =
1717
, "tar" : process.env.TAR || "tar"
1818
, "gzipbin" : process.env.GZIPBIN || "gzip"
1919
, tag : "latest"
20-
, proxy : process.env.http_proxy ? ("http://" + process.env.http_proxy) : null
20+
, proxy : process.env.http_proxy || null
2121
, root : path.join(process.execPath, "..", "..", "lib", "node")
2222
, globalconfig : path.join(process.execPath, "..", "..", "etc", "npmrc")
2323
, userconfig : path.join(process.env.HOME, ".npmrc")

lib/utils/fetch.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,19 @@ function fetchAndWrite (remote, fd, headers, maxRedirects, redirects, cb) {
3535
set(headers, "host", remote.hostname)
3636
remote.path = remote.pathname+(remote.search||"")+(remote.hash||"")
3737
var proxyConfig = npm.config.get("proxy")
38-
, proxy = (proxyConfig) ? url.parse(proxyConfig) : null
39-
, https = (proxy || remote).protocol === "https:"
38+
if (proxyConfig) {
39+
if (!proxyConfig.match(/^https?:\/\//)) {
40+
proxyConfig = remote.protocol+"//"+proxyConfig
41+
}
42+
var proxy = (proxyConfig) ? url.parse(proxyConfig) : null
43+
if (!proxy.host) return cb(new Error("Bad proxy config: "+proxyConfig))
44+
}
45+
var https = (proxy || remote).protocol === "https:"
4046
, port = (proxy || remote).port || (https ? 443 : 80)
4147
, hostname = (proxy || remote).hostname
42-
, path = proxy ? remote.href : (remote.pathname||"/")+(remote.search||"")+(remote.hash||"")
48+
, path = proxy ? remote.href : (remote.pathname||"/")
49+
+ (remote.search||"")
50+
+ (remote.hash||"")
4351
http
4452
.createClient(port, hostname, https)
4553
.request( "GET", path, headers)

lib/utils/registry/request.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ function request (method, where, what, cb) {
2626
where = url.resolve(npm.config.get("registry"), where)
2727
var u = url.parse(where)
2828
, proxyConfig = npm.config.get("proxy")
29-
, proxy = (proxyConfig) ? url.parse(proxyConfig) : null
30-
, https = (proxy || u).protocol === "https:"
29+
if (proxyConfig) {
30+
if (!proxyConfig.match(/^https?:\/\//)) {
31+
proxyConfig = u.protocol+"//"+proxyConfig
32+
}
33+
var proxy = (proxyConfig) ? url.parse(proxyConfig) : null
34+
if (!proxy.host) return cb(new Error("Bad proxy config: "+proxyConfig))
35+
}
36+
var https = (proxy || u).protocol === "https:"
3137
, port = (proxy || u).port || (https ? 443 : 80)
3238
, hostname = (proxy || u).hostname
3339
, client = http.createClient(port, hostname, https)

0 commit comments

Comments
 (0)