diff options
author | isaacs <i@izs.me> | 2014-05-06 03:16:51 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2014-05-06 03:16:51 +0400 |
commit | aca48cfbe5c3e838ba295a400cf2fa087f4d44bd (patch) | |
tree | bfe8e300374492504a62dfa7487f540233bf34a0 /lib | |
parent | 7bf62b542f7998463bc264be871a918fffa8ffb3 (diff) |
fetch: Send referer and npm-session headers
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utils/fetch.js | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/utils/fetch.js b/lib/utils/fetch.js index e92b68d14..f6e5166ff 100644 --- a/lib/utils/fetch.js +++ b/lib/utils/fetch.js @@ -12,6 +12,7 @@ var request = require("request") , chownr = require("chownr") , regHost , once = require("once") + , crypto = require("crypto") module.exports = fetch @@ -78,12 +79,24 @@ function makeRequest (remote, fstr, headers) { proxy = npm.config.get("proxy") } + var sessionToken = npm.registry.sessionToken + if (!sessionToken) { + sessionToken = crypto.randomBytes(8).toString("hex") + npm.registry.sessionToken = sessionToken + } + + var ca = remote.host === regHost ? npm.config.get("ca") : undefined var opts = { url: remote , proxy: proxy , strictSSL: npm.config.get("strict-ssl") , rejectUnauthorized: npm.config.get("strict-ssl") - , ca: remote.host === regHost ? npm.config.get("ca") : undefined - , headers: { "user-agent": npm.config.get("user-agent") }} + , ca: ca + , headers: + { "user-agent": npm.config.get("user-agent") + , "npm-session": sessionToken + , referer: npm.registry.refer + } + } var req = request(opts) req.on("error", function (er) { fstr.emit("error", er) |