Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove referer header and opts.refer #25

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions README.md
Expand Up @@ -501,14 +501,6 @@ using
If the request URI already has a query string, it will be merged with
`opts.query`, preferring `opts.query` values.

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

* Type: String
* Default: null

Value to use for the `Referer` header. The npm CLI itself uses this to serialize
the npm command line using the given request.

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

* Type: URL
Expand Down
14 changes: 9 additions & 5 deletions index.js
Expand Up @@ -113,7 +113,6 @@ function regFetch (uri, /* istanbul ignore next */ opts_ = {}) {
method: method,
noProxy: opts.noProxy,
proxy: opts.httpsProxy || opts.proxy,
referer: opts.refer,
retry: opts.retry ? opts.retry : {
retries: opts.fetchRetries,
factor: opts.fetchRetryFactor,
Expand Down Expand Up @@ -176,12 +175,17 @@ function getCacheMode (opts) {
function getHeaders (registry, uri, opts) {
const headers = Object.assign({
'npm-in-ci': !!opts.isFromCI,
'npm-scope': opts.projectScope,
'npm-session': opts.npmSession,
'user-agent': opts.userAgent,
referer: opts.refer
'user-agent': opts.userAgent
}, opts.headers || {})

if (opts.projectScope) {
headers['npm-scope'] = opts.projectScope
}

if (opts.npmSession) {
headers['npm-session'] = opts.npmSession
}

const auth = getAuth(registry, opts)
// If a tarball is hosted on a different place than the manifest, only send
// credentials on `alwaysAuth`
Expand Down
24 changes: 22 additions & 2 deletions test/index.js
Expand Up @@ -497,6 +497,26 @@ test('npm-in-ci header with forced CI=false', t => {
// TODO
// * npm-session
// * npm-scope
// * referer (opts.refer)
// * user-agent
test('miscellaneous headers')
test('miscellaneous headers', t => {
tnock(t, OPTS.registry)
.matchHeader('npm-session', session =>
t.strictSame(session, ['foobarbaz'], 'session set from options'))
.matchHeader('npm-scope', scope =>
t.strictSame(scope, ['@foo'], 'scope set from options'))
.matchHeader('user-agent', ua =>
t.strictSame(ua, ['agent of use'], 'UA set from options'))
.matchHeader('npm-in-ci', ci =>
t.strictSame(ci, ['false'], 'CI set from options'))
.get('/hello')
.reply(200, { hello: 'world' })

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