зеркало из https://github.com/github/docs.git
remove catch-bad-accept-language middleware (#25231)
This commit is contained in:
Родитель
d02feb0ab5
Коммит
24d3ea6814
|
@ -1,15 +0,0 @@
|
|||
import accept from '@hapi/accept'
|
||||
|
||||
// Next.JS uses the @hapi/accept package to parse and detect languages. If the accept-language header is malformed
|
||||
// it throws an error from within Next.JS, which results in a 500 response. This ends up being noisy because we
|
||||
// track 500s. To counteract this, we'll try to catch the error first and make sure it doesn't happen
|
||||
export default function catchBadAcceptLanguage(req, res, next) {
|
||||
try {
|
||||
accept.language(req.headers['accept-language'])
|
||||
} catch (e) {
|
||||
// if there's a problem with parsing 'accept-language', just clear it out.
|
||||
req.headers['accept-language'] = ''
|
||||
}
|
||||
|
||||
return next()
|
||||
}
|
|
@ -17,7 +17,6 @@ import csrf from './csrf.js'
|
|||
import handleCsrfErrors from './handle-csrf-errors.js'
|
||||
import { setDefaultFastlySurrogateKey } from './set-fastly-surrogate-key.js'
|
||||
import setFastlyCacheHeaders from './set-fastly-cache-headers.js'
|
||||
import catchBadAcceptLanguage from './catch-bad-accept-language.js'
|
||||
import reqUtils from './req-utils.js'
|
||||
import recordRedirect from './record-redirect.js'
|
||||
import connectSlashes from 'connect-slashes'
|
||||
|
@ -207,7 +206,6 @@ export default function (app) {
|
|||
|
||||
// *** Headers ***
|
||||
app.set('etag', false) // We will manage our own ETags if desired
|
||||
app.use(catchBadAcceptLanguage)
|
||||
|
||||
// *** Config and context for redirects ***
|
||||
app.use(reqUtils) // Must come before record-redirect and events
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
"license": "(MIT AND CC-BY-4.0)",
|
||||
"dependencies": {
|
||||
"@github/failbot": "0.8.0",
|
||||
"@hapi/accept": "^5.0.2",
|
||||
"@primer/components": "^33.1.0",
|
||||
"@primer/css": "^19.1.1",
|
||||
"@primer/octicons": "^16.3.0",
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
],
|
||||
"dependencies": {
|
||||
"@github/failbot": "0.8.0",
|
||||
"@hapi/accept": "^5.0.2",
|
||||
"@primer/components": "^33.1.0",
|
||||
"@primer/css": "^19.1.1",
|
||||
"@primer/octicons": "^16.3.0",
|
||||
|
|
|
@ -664,6 +664,24 @@ describe('server', () => {
|
|||
)
|
||||
})
|
||||
|
||||
// This test exists because in a previous life, our NextJS used to
|
||||
// 500 if the 'Accept-Language' header was malformed.
|
||||
// We *used* have a custom middleware to cope with this and force a
|
||||
// fallback redirect.
|
||||
// See internal issue 19909
|
||||
test('redirects /en if Accept-Language header is malformed', async () => {
|
||||
const res = await get('/', {
|
||||
headers: {
|
||||
'accept-language': 'ldfir;',
|
||||
},
|
||||
})
|
||||
|
||||
expect(res.statusCode).toBe(302)
|
||||
expect(res.headers.location).toBe('/en')
|
||||
expect(res.headers['cache-control']).toBe('private, no-store')
|
||||
expect(res.headers['set-cookie']).toBeUndefined()
|
||||
})
|
||||
|
||||
test('redirects / to /en when unsupported language preference is specified', async () => {
|
||||
const res = await get('/', {
|
||||
headers: {
|
||||
|
|
Загрузка…
Ссылка в новой задаче