Skip to content

Commit

Permalink
feat: add npm-command HTTP header
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed May 20, 2020
1 parent 022c909 commit 1bb4eb2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,15 @@ If provided, will be sent in the `npm-session` header. This header is used by
the npm registry to identify individual user sessions (usually individual
invocations of the CLI).

##### <a name="opts-npmCommand"></a> `opts.npmCommand`

* Type: String
* Default: null

If provided, it will be sent in the `npm-command` header. This yeader is
used by the npm registry to identify the npm command that caused this
request to be made.

##### <a name="opts-offline"></a> `opts.offline`

* Type: Boolean
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ function getHeaders (registry, uri, opts) {
headers['npm-session'] = opts.npmSession
}

if (opts.npmCommand) {
headers['npm-command'] = opts.npmCommand
}

const auth = getAuth(registry, opts)
// If a tarball is hosted on a different place than the manifest, only send
// credentials on `alwaysAuth`
Expand Down
9 changes: 4 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,6 @@ test('npm-in-ci header with forced CI=false', t => {
})
})

// TODO
// * npm-session
// * npm-scope
// * user-agent
test('miscellaneous headers', t => {
tnock(t, OPTS.registry)
.matchHeader('npm-session', session =>
Expand All @@ -508,14 +504,17 @@ test('miscellaneous headers', t => {
t.strictSame(ua, ['agent of use'], 'UA set from options'))
.matchHeader('npm-in-ci', ci =>
t.strictSame(ci, ['false'], 'CI set from options'))
.matchHeader('npm-command', cmd =>
t.strictSame(cmd, ['hello-world'], 'command set from options'))
.get('/hello')
.reply(200, { hello: 'world' })

return fetch('/hello', {
...OPTS,
npmSession: 'foobarbaz',
projectScope: '@foo',
userAgent: 'agent of use'
userAgent: 'agent of use',
npmCommand: 'hello-world'
}).then(res => {
t.equal(res.status, 200, 'got successful response')
})
Expand Down

0 comments on commit 1bb4eb2

Please sign in to comment.