Permalink
Browse files

Closes GH-753 Set the host header properly with port

  • Loading branch information...
1 parent c40381a commit 0b5786d5d06b13b97b145ad0f6732a84cd81c7fb @isaacs isaacs committed Mar 28, 2011
Showing with 14 additions and 8 deletions.
  1. +5 −2 lib/utils/fetch.js
  2. +6 −3 lib/utils/proxyify.js
  3. +3 −3 lib/utils/registry/request.js
View
@@ -48,16 +48,19 @@ function fetchAndWrite (remote, fstr, headers, maxRedirects, redirects) {
if (!maxRedirects) maxRedirects = 10
var remote = url.parse(remote)
, opts =
- { headers: headers
+ { headers: headers || {}
, path: (remote.pathname||"/")+(remote.search||"")+(remote.hash||"")
, host: remote.hostname
, port: remote.port
, secure: remote.protocol.toLowerCase() === "https:"
//FIXME: this sucks.
, agent: false
}
+
if (!opts.port) opts.port = opts.secure ? 443 : 80
- if (opts.port !== (opts.secure ? 443 : 80)) opts.host += ":" + opts.port
+ if (opts.port !== (opts.secure ? 443 : 80)) {
+ opts.headers.host = opts.host + ":" + opts.port
+ }
opts = proxyify(npm.config.get("proxy"), remote, opts)
if (!opts) return cb(new Error("Bad proxy config: "+npm.config.get("proxy")))
View
@@ -26,23 +26,26 @@ function proxyify (proxyConfig, remote, opts) {
"Basic " + (new Buffer(proxy.auth).toString("base64"))
}
+ if (typeof remote === "string") remote = url.parse(remote)
+
opts.headers.host = remote.hostname
opts.host = proxy.hostname
opts.port = +(proxy.port ? proxy.port
:proxy.protocol === "https:" ? 443
:80)
- if (opts.port !== (proxy.protocol === "https:" ? 443 : 80)) {
- opts.host += ":" + proxy.port
+ if (remote.port &&
+ remote.port !== (remote.protocol === "https:" ? 443 : 80)) {
+ opts.headers.host = remote.hostname + ":" + remote.port
}
- if (typeof remote === "string") remote = url.parse(remote)
if (remote.auth) {
headers.authorization = (new Buffer(remote.auth).toString("base64"))
delete remote.href
delete remote.host
delete remote.auth
}
+
opts.path = url.format(remote)
opts.secure = proxy.protocol === "https:"
@@ -97,9 +97,6 @@ function request (method, where, what, etag, nofollow, cb_) {
headers[method === "GET" ? "if-none-match" : "if-match"] = etag
}
- log.silly(headers, "headers")
- log.silly(remote, "remote")
-
if (!remote.protocol) log.warn(remote, "No protocol?")
var opts = { method: method
@@ -113,6 +110,9 @@ function request (method, where, what, etag, nofollow, cb_) {
, port: remote.port
}
if (!opts.port) opts.port = opts.secure ? 443 : 80
+ if (opts.port !== (opts.secure ? 443 : 80)) {
+ opts.headers.host += ":" + opts.port
+ }
opts = proxyify(npm.config.get("proxy"), remote, opts)
if (!opts) return cb(new Error("Bad proxy config: "+npm.config.get("proxy")))

0 comments on commit 0b5786d

Please sign in to comment.