Skip to content

Commit

Permalink
Update 404 static cache header to not cache (vercel#5146)
Browse files Browse the repository at this point in the history
  • Loading branch information
linqiu authored and timneutkens committed Sep 12, 2018
1 parent 873ac5d commit 3f650e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ export default class Server {
async render404 (req, res, parsedUrl = parseUrl(req.url, true)) {
const { pathname, query } = parsedUrl
res.statusCode = 404
res.setHeader('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate')
return this.renderError(null, req, res, pathname, query)
}

Expand Down
8 changes: 8 additions & 0 deletions test/integration/production/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
const urls = ['/_document', '/_error']
for (const url of urls) {
Expand Down

0 comments on commit 3f650e1

Please sign in to comment.