Permalink
Browse files

Add debuggery around proxy stuff

  • Loading branch information...
1 parent a7bec5a commit 43badf583986d6317622bffd6c19305cc8287f73 @isaacs isaacs committed Feb 22, 2011
Showing with 24 additions and 1 deletion.
  1. +1 −1 lib/utils/fetch.js
  2. +21 −0 lib/utils/proxyify.js
  3. +2 −0 lib/utils/registry/request.js
View
@@ -67,10 +67,10 @@ function fetchAndWrite (remote, fstr, headers, maxRedirects, redirects) {
delete remote.auth
}
+ log.verbose(remote, "proxyifying")
opts = proxyify(remote, opts)
if (!opts) return cb(new Error("Bad proxy config: "+npm.config.get("proxy")))
-
;(opts.secure ? https : http).get(opts, function (response) {
// handle redirects.
var loc = get(response.headers, "location")
View
@@ -3,30 +3,51 @@ module.exports = proxyify
var npm = require("../../npm")
, url = require("url")
+ , log = require("./log")
var proxy
function proxyify (remote, opts) {
if (proxy === false) return opts
if (!proxy) {
var proxyConfig = npm.config.get("proxy")
if (!proxyConfig) {
+ log.verbose(proxyConfig, "no proxy")
proxy = false
return opts
}
+ log.verbose(proxyConfig, "proxy config")
if (!proxyConfig.match(/^https?:\/\//)) {
proxyConfig = remote.protocol + "//" + proxyConfig
}
proxy = url.parse(proxyConfig)
if (!proxy) {
+ log.warn(proxyConfig, "invalid proxy config")
return null
}
}
if (proxy.auth) {
opts.headers["proxy-authorization"] =
"Basic " + (new Buffer(proxy.auth).toString("base64"))
+
+ //TODO: remove debuggery
+ var unpw = proxy.auth.split(":")
+ , un = unpw.shift()
+ , pw = unpw.join(":")
+ log.verbose([un, pw?"****":"<no password>"], "proxy auth")
}
opts.headers.host = proxy.hostname
opts.path = url.format(remote)
opts.secure = proxy.protocol === "https:"
+
+ //TODO: remove debuggery
+ var o = {headers:{}}
+ for (var i in opts) if (i !== "headers") o[i] = opts[i]
+ if (opts.headers) for (var i in opts.headers) o.headers[i] = opts.headers[i]
+ if (o.headers.authorization) o.headers.authorization = "<hidden>"
+ if (o.headers["proxy-authorization"]) {
+ o.headers["proxy-authorization"] = "<hidden>"
+ }
+ log.verbose(o, "modified opts for proxy")
+
return opts
}
@@ -106,6 +106,8 @@ function request (method, where, what, etag, nofollow, cb_) {
, port: remote.port
}
if (!opts.port) opts.port = opts.secure ? 443 : 80
+
+ log.verbose(remote, "about to proxyify")
opts = proxyify(remote, opts)
if (!opts) return cb(new Error("Bad proxy config: "+npm.config.get("proxy")))

0 comments on commit 43badf5

Please sign in to comment.