Skip to content

Commit 1bb4eb2

Browse files
committed
feat: add npm-command HTTP header
1 parent 022c909 commit 1bb4eb2

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,15 @@ If provided, will be sent in the `npm-session` header. This header is used by
398398
the npm registry to identify individual user sessions (usually individual
399399
invocations of the CLI).
400400

401+
##### <a name="opts-npmCommand"></a> `opts.npmCommand`
402+
403+
* Type: String
404+
* Default: null
405+
406+
If provided, it will be sent in the `npm-command` header. This yeader is
407+
used by the npm registry to identify the npm command that caused this
408+
request to be made.
409+
401410
##### <a name="opts-offline"></a> `opts.offline`
402411

403412
* Type: Boolean

index.js

+4
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ function getHeaders (registry, uri, opts) {
186186
headers['npm-session'] = opts.npmSession
187187
}
188188

189+
if (opts.npmCommand) {
190+
headers['npm-command'] = opts.npmCommand
191+
}
192+
189193
const auth = getAuth(registry, opts)
190194
// If a tarball is hosted on a different place than the manifest, only send
191195
// credentials on `alwaysAuth`

test/index.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,6 @@ test('npm-in-ci header with forced CI=false', t => {
494494
})
495495
})
496496

497-
// TODO
498-
// * npm-session
499-
// * npm-scope
500-
// * user-agent
501497
test('miscellaneous headers', t => {
502498
tnock(t, OPTS.registry)
503499
.matchHeader('npm-session', session =>
@@ -508,14 +504,17 @@ test('miscellaneous headers', t => {
508504
t.strictSame(ua, ['agent of use'], 'UA set from options'))
509505
.matchHeader('npm-in-ci', ci =>
510506
t.strictSame(ci, ['false'], 'CI set from options'))
507+
.matchHeader('npm-command', cmd =>
508+
t.strictSame(cmd, ['hello-world'], 'command set from options'))
511509
.get('/hello')
512510
.reply(200, { hello: 'world' })
513511

514512
return fetch('/hello', {
515513
...OPTS,
516514
npmSession: 'foobarbaz',
517515
projectScope: '@foo',
518-
userAgent: 'agent of use'
516+
userAgent: 'agent of use',
517+
npmCommand: 'hello-world'
519518
}).then(res => {
520519
t.equal(res.status, 200, 'got successful response')
521520
})

0 commit comments

Comments
 (0)