Permalink
Browse files

Adding configurable user-agent to request header

  • Loading branch information...
1 parent d3320ac commit 737152b17ff080ef3d6540045749f51971482f5b @jensgrunert committed Apr 4, 2012
Showing with 13 additions and 0 deletions.
  1. +7 −0 doc/cli/config.md
  2. +3 −0 lib/utils/config-defs.js
  3. +3 −0 lib/utils/npm-registry-client/request.js
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} node/{process.version}
+* Type: String
+
+Sets a User-Agent to the request header
+
### ignore
* Default: ""
View
3 lib/utils/config-defs.js
@@ -9,6 +9,7 @@ var path = require("path")
, os = require("os")
, nopt = require("nopt")
, log = require("./log.js")
+ , npm = require("../npm.js")
function Octal () {}
function validateOctal (data, k, val) {
@@ -183,6 +184,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/" + npm.version + " node/" + process.version
, "rebuild-bundle" : true
, registry : "http" + (httpsOk ? "s" : "") + "://registry.npmjs.org/"
, rollback : true
@@ -239,6 +241,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
3 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) {
@@ -94,6 +95,8 @@ function makeRequest (method, remote, where, what, etag, nofollow, cb) {
headers.accept = "application/json"
+ headers["User-Agent"] = opts.userAgent
+
opts.proxy = npm.config.get( remote.protocol === "https:"
? "https-proxy" : "proxy" )

0 comments on commit 737152b

Please sign in to comment.