1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Update 404 static cache header to not cache (#5146)

This commit is contained in:
Lin Qiu 2018-09-12 08:44:15 -04:00 committed by Tim Neutkens
parent 873ac5dba8
commit 3f650e1549
2 changed files with 9 additions and 0 deletions

View file

@ -310,6 +310,7 @@ export default class Server {
async render404 (req, res, parsedUrl = parseUrl(req.url, true)) { async render404 (req, res, parsedUrl = parseUrl(req.url, true)) {
const { pathname, query } = parsedUrl const { pathname, query } = parsedUrl
res.statusCode = 404 res.statusCode = 404
res.setHeader('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate')
return this.renderError(null, req, res, pathname, query) return this.renderError(null, req, res, pathname, query)
} }

View file

@ -91,6 +91,14 @@ describe('Production Usage', () => {
}) })
}) })
it('should set correct Cache-Control header for static 404s', async () => {
// this is to fix where 404 headers are set to 'public, max-age=31536000, immutable'
const res = await fetch(`http://localhost:${appPort}/_next//static/common/bad-static.js`)
expect(res.status).toBe(404)
expect(res.headers.get('Cache-Control')).toBe('no-cache, no-store, max-age=0, must-revalidate')
})
it('should block special pages', async () => { it('should block special pages', async () => {
const urls = ['/_document', '/_error'] const urls = ['/_document', '/_error']
for (const url of urls) { for (const url of urls) {