Commit 3f650e15 authored by Lin Qiu's avatar Lin Qiu Committed by Tim Neutkens

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

parent 873ac5db
...@@ -310,6 +310,7 @@ export default class Server { ...@@ -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)
} }
......
...@@ -91,6 +91,14 @@ describe('Production Usage', () => { ...@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment