Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jensgrunert/npm
...
head fork: jensgrunert/npm
  • 2 commits
  • 5 files changed
  • 3 commit comments
  • 1 contributor
View
7 doc/cli/config.md
@@ -358,6 +358,13 @@ user.
A proxy to use for outgoing https requests.
+### user-agent
+
+* Default: NPM/{npm-version}
+* Type: String
+
+Sets a User-Agent to the request header
+
### ignore
* Default: ""
View
2  lib/utils/config-defs.js
@@ -183,6 +183,7 @@ Object.defineProperty(exports, "defaults", {get: function () {
, proxy : process.env.HTTP_PROXY || process.env.http_proxy || null
, "https-proxy" : process.env.HTTPS_PROXY || process.env.https_proxy ||
process.env.HTTP_PROXY || process.env.http_proxy || null
+ , "user-agent" : "NPM/"+process.version
, "rebuild-bundle" : true
, registry : "http" + (httpsOk ? "s" : "") + "://registry.npmjs.org/"
, rollback : true
@@ -239,6 +240,7 @@ exports.types =
, globalignorefile: path
, group : [Number, String]
, "https-proxy" : [null, url]
+ , "user-agent" : String
, ignore : String
, "init.version" : [null, semver]
, "init.author.name" : String
View
1  lib/utils/fetch.js
@@ -58,6 +58,7 @@ function makeRequest (remote, fstr, headers) {
request({ url: remote
, proxy: proxy
, strictSSL: npm.config.get("strict-ssl")
+ , userAgent: npm.config.get("user-agent")
, ca: remote.host === regHost ? npm.config.get("ca") : undefined
, onResponse: onResponse }).pipe(fstr)
function onResponse (er, res) {
View
1  lib/utils/npm-registry-client/request.js
@@ -85,6 +85,7 @@ function makeRequest (method, remote, where, what, etag, nofollow, cb) {
var opts = { url: remote
, method: method
, ca: npm.config.get("ca")
+ , userAgent: npm.config.get("user-agent")
, strictSSL: npm.config.get("strict-ssl") }
, headers = opts.headers = {}
if (etag) {
View
4 node_modules/request/main.js
@@ -244,6 +244,10 @@ Request.prototype.init = function (options) {
self.multipart(options.multipart)
}
+ if (self.userAgent) {
+ self.headers['User-Agent'] = self.userAgent
+ }
+
if (self.body) {
var length = 0
if (!Buffer.isBuffer(self.body)) {

Showing you all comments on commits in this comparison.

@isaacs

Should be lowercase, and provide both the npm and node version. How about "npm@" + npm.version + "; node@" + process.version?

@isaacs

Add a "user-agent" field to the headers object, not a new request option.

@isaacs

Changes to the request library should go upstream, not here. I try to keep npm's request as close to a vanilla install as possible.

Something went wrong with that request. Please try again.