Skip to content

Commit a5aad1f

Browse files
authored
BREAKING CHANGE: remove handling of deprecated warning headers (#53)
1 parent 9a5b7eb commit a5aad1f

File tree

5 files changed

+0
-86
lines changed

5 files changed

+0
-86
lines changed

check-response.js

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

33
const errors = require('./errors.js')
4-
const LRU = require('lru-cache')
54
const { Response } = require('minipass-fetch')
65
const defaultOpts = require('./default-opts.js')
76

@@ -10,7 +9,6 @@ const checkResponse = async ({ method, uri, res, registry, startTime, auth, opts
109
if (res.headers.has('npm-notice') && !res.headers.has('x-local-cache'))
1110
opts.log.notice('', res.headers.get('npm-notice'))
1211

13-
checkWarnings(res, registry, opts)
1412
if (res.status >= 400) {
1513
logRequest(method, res, startTime, opts)
1614
if (auth && auth.scopeAuthKey && !auth.token && !auth.auth) {
@@ -60,46 +58,6 @@ function logRequest (method, res, startTime, opts) {
6058
)
6159
}
6260

63-
const WARNING_REGEXP = /^\s*(\d{3})\s+(\S+)\s+"(.*)"\s+"([^"]+)"/
64-
const BAD_HOSTS = new LRU({ max: 50 })
65-
66-
function checkWarnings (res, registry, opts) {
67-
if (res.headers.has('warning') && !BAD_HOSTS.has(registry)) {
68-
const warnings = {}
69-
// note: headers.raw() will preserve case, so we might have a
70-
// key on the object like 'WaRnInG' if that was used first
71-
for (const [key, value] of Object.entries(res.headers.raw())) {
72-
if (key.toLowerCase() !== 'warning')
73-
continue
74-
value.forEach(w => {
75-
const match = w.match(WARNING_REGEXP)
76-
if (match) {
77-
warnings[match[1]] = {
78-
code: match[1],
79-
host: match[2],
80-
message: match[3],
81-
date: new Date(match[4]),
82-
}
83-
}
84-
})
85-
}
86-
BAD_HOSTS.set(registry, true)
87-
if (warnings['199']) {
88-
if (warnings['199'].message.match(/ENOTFOUND/))
89-
opts.log.warn('registry', `Using stale data from ${registry} because the host is inaccessible -- are you offline?`)
90-
else
91-
opts.log.warn('registry', `Unexpected warning for ${registry}: ${warnings['199'].message}`)
92-
}
93-
if (warnings['111']) {
94-
// 111 Revalidation failed -- we're using stale data
95-
opts.log.warn(
96-
'registry',
97-
`Using stale data from ${registry} due to a request error during revalidation.`
98-
)
99-
}
100-
}
101-
}
102-
10361
function checkErrors (method, res, startTime, opts) {
10462
return res.buffer()
10563
.catch(() => null)

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
},
3030
"license": "ISC",
3131
"dependencies": {
32-
"lru-cache": "^6.0.0",
3332
"make-fetch-happen": "^8.0.9",
3433
"minipass": "^3.1.3",
3534
"minipass-fetch": "^1.3.0",

test/check-response.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -135,30 +135,6 @@ t.test('redact password from log', t => {
135135
res.body.emit('end')
136136
})
137137

138-
t.test('bad-formatted warning headers', t => {
139-
const headers = new Headers()
140-
headers.has = header => header === 'warning' ? 'foo' : undefined
141-
headers.raw = () => ({
142-
warning: ['100 - foo'],
143-
})
144-
const res = Object.assign({}, mockFetchRes, {
145-
headers,
146-
})
147-
return t.resolves(checkResponse({
148-
method: 'get',
149-
res,
150-
registry,
151-
startTime,
152-
opts: {
153-
log: Object.assign({}, silentLog, {
154-
warn (header, msg) {
155-
t.fail('should not log warnings')
156-
},
157-
}),
158-
},
159-
}))
160-
})
161-
162138
t.test('report auth for registry, but not for this request', t => {
163139
const res = Object.assign({}, mockFetchRes, {
164140
buffer: () => Promise.resolve(Buffer.from('ok')),

test/index.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -466,24 +466,6 @@ t.test('pickRegistry through opts.spec', t => {
466466
))
467467
})
468468

469-
t.test('log warning header info', t => {
470-
tnock(t, defaultOpts.registry)
471-
.get('/hello')
472-
.reply(200, { hello: 'world' }, { Warning: '199 - "ENOTFOUND" "Wed, 21 Oct 2015 07:28:00 GMT"' })
473-
const opts = {
474-
...OPTS,
475-
log: Object.assign({}, silentLog, {
476-
warn (header, msg) {
477-
t.equal(header, 'registry', 'expected warn log header')
478-
t.equal(msg, `Using stale data from ${defaultOpts.registry} because the host is inaccessible -- are you offline?`, 'logged out at WARNING level')
479-
},
480-
}),
481-
}
482-
t.plan(3)
483-
return fetch('/hello', opts)
484-
.then(res => t.equal(res.status, 200, 'got successful response'))
485-
})
486-
487469
t.test('miscellaneous headers', t => {
488470
tnock(t, defaultOpts.registry)
489471
.matchHeader('npm-session', session =>

0 commit comments

Comments
 (0)