Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Report 404 errors properly with non-vhosted registries

  • Loading branch information...
commit 8923b80796770da810f41b93634c4bbb6a8f2482 1 parent f451082
@isaacs isaacs authored
Showing with 11 additions and 3 deletions.
  1. +11 −3 lib/utils/npm-registry-client/request.js
View
14 lib/utils/npm-registry-client/request.js
@@ -81,10 +81,12 @@ function request (method, where, what, etag, nofollow, cb_) {
"Cannot insert data into the registry without authorization\n"
+ "See: npm-adduser(1)"))
}
+
if (auth && !secure && !warnedAuth) {
warnedAuth = true
log.warn("Sending authorization over insecure channel.")
}
+
var headers = { "accept" : "application/json" }
if (auth) headers.authorization = "Basic " + auth
if (what) {
@@ -101,6 +103,7 @@ function request (method, where, what, etag, nofollow, cb_) {
} else {
headers["content-length"] = 0
}
+
if (etag) {
log.verbose(etag, "etag")
headers[method === "GET" ? "if-none-match" : "if-match"] = etag
@@ -132,14 +135,14 @@ function request (method, where, what, etag, nofollow, cb_) {
var req = (opts.secure ? https : http).request(opts, function (response) {
log.verbose(where, "response")
- // if (response.statusCode !== 200) return cb(new Error(
- // "Status code " + response.statusCode + " from PUT "+where))
+
var data = ""
response.on("error", log.er(cb, "response error from "+where))
response.on("data", function (chunk) {
log.silly(chunk+"", "chunk")
data += chunk
})
+
global.newloctimeout = global.newloctimeout || 0
response.on("end", function () {
if (!nofollow
@@ -157,6 +160,7 @@ function request (method, where, what, etag, nofollow, cb_) {
log.er(cb, "Failed to fetch "+newLoc))
}, 1000*(global.newloctimeout ++))
}
+
var parsed
if (response.statusCode !== 304) {
try {
@@ -168,14 +172,17 @@ function request (method, where, what, etag, nofollow, cb_) {
return cb(ex, null, data, response)
}
}
+
var er = null
if (parsed && response.headers.etag) {
parsed._etag = response.headers.etag
}
+
if (parsed && parsed.error) {
var w = url.parse(where).pathname.substr(1)
- , name = w.split("/")[0]
if (parsed.error === "not_found") {
+ w = w.split("/")
+ name = w[w.indexOf("_rewrite") + 1]
er = new Error("404 Not Found: "+name)
er.errno = npm.E404
er.pkgid = name
@@ -184,6 +191,7 @@ function request (method, where, what, etag, nofollow, cb_) {
parsed.error + " " + (parsed.reason || "") + ": " + w)
}
} else if (method !== "HEAD" && method !== "GET") {
+
// invalidate cache
// This is irrelevant for commands that do etag caching, but
// ls and view also have a timed cache, so this keeps the user
Please sign in to comment.
Something went wrong with that request. Please try again.