Skip to content

Commit eb8f7af

Browse files
committed
fix: remove referer header and opts.refer
Re: npm/cli#930 BREAKING CHANGE: Removes the 'opts.refer' option and the HTTP Referer header (unless explicitly added to the 'headers' option, of course). PR-URL: #25 Credit: @isaacs Close: #25 Reviewed-by: @mikemimik
1 parent 3186645 commit eb8f7af

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

README.md

-8
Original file line numberDiff line numberDiff line change
@@ -501,14 +501,6 @@ using
501501
If the request URI already has a query string, it will be merged with
502502
`opts.query`, preferring `opts.query` values.
503503

504-
##### <a name="opts-refer"></a> `opts.refer`
505-
506-
* Type: String
507-
* Default: null
508-
509-
Value to use for the `Referer` header. The npm CLI itself uses this to serialize
510-
the npm command line using the given request.
511-
512504
##### <a name="opts-registry"></a> `opts.registry`
513505

514506
* Type: URL

index.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ function regFetch (uri, /* istanbul ignore next */ opts_ = {}) {
113113
method: method,
114114
noProxy: opts.noProxy,
115115
proxy: opts.httpsProxy || opts.proxy,
116-
referer: opts.refer,
117116
retry: opts.retry ? opts.retry : {
118117
retries: opts.fetchRetries,
119118
factor: opts.fetchRetryFactor,
@@ -176,12 +175,17 @@ function getCacheMode (opts) {
176175
function getHeaders (registry, uri, opts) {
177176
const headers = Object.assign({
178177
'npm-in-ci': !!opts.isFromCI,
179-
'npm-scope': opts.projectScope,
180-
'npm-session': opts.npmSession,
181-
'user-agent': opts.userAgent,
182-
referer: opts.refer
178+
'user-agent': opts.userAgent
183179
}, opts.headers || {})
184180

181+
if (opts.projectScope) {
182+
headers['npm-scope'] = opts.projectScope
183+
}
184+
185+
if (opts.npmSession) {
186+
headers['npm-session'] = opts.npmSession
187+
}
188+
185189
const auth = getAuth(registry, opts)
186190
// If a tarball is hosted on a different place than the manifest, only send
187191
// credentials on `alwaysAuth`

test/index.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,26 @@ test('npm-in-ci header with forced CI=false', t => {
497497
// TODO
498498
// * npm-session
499499
// * npm-scope
500-
// * referer (opts.refer)
501500
// * user-agent
502-
test('miscellaneous headers')
501+
test('miscellaneous headers', t => {
502+
tnock(t, OPTS.registry)
503+
.matchHeader('npm-session', session =>
504+
t.strictSame(session, ['foobarbaz'], 'session set from options'))
505+
.matchHeader('npm-scope', scope =>
506+
t.strictSame(scope, ['@foo'], 'scope set from options'))
507+
.matchHeader('user-agent', ua =>
508+
t.strictSame(ua, ['agent of use'], 'UA set from options'))
509+
.matchHeader('npm-in-ci', ci =>
510+
t.strictSame(ci, ['false'], 'CI set from options'))
511+
.get('/hello')
512+
.reply(200, { hello: 'world' })
513+
514+
return fetch('/hello', {
515+
...OPTS,
516+
npmSession: 'foobarbaz',
517+
projectScope: '@foo',
518+
userAgent: 'agent of use'
519+
}).then(res => {
520+
t.equal(res.status, 200, 'got successful response')
521+
})
522+
})

0 commit comments

Comments
 (0)