Add support for 412 Precondition Failed status for static files (#7944)

* Add support for Precondition Failed status for static files

* Add test

* Trigger tests

* Update next-server.ts
This commit is contained in:
Adam Misiorny 2019-07-16 13:30:29 +02:00 committed by Tim Neutkens
parent e5e74dabdc
commit 90280c864b
2 changed files with 18 additions and 0 deletions

View file

@ -648,6 +648,9 @@ export default class Server {
} catch (err) {
if (err.code === 'ENOENT' || err.statusCode === 404) {
this.render404(req, res, parsedUrl)
} else if (err.statusCode === 412) {
res.statusCode = 412
return this.renderError(err, req, res, path)
} else {
throw err
}

View file

@ -126,6 +126,21 @@ describe('Production Usage', () => {
expect(res.status).toBe(405)
})
it('should return 412 method on static file if If-Unmodified-Since is invalid', async () => {
const buildId = readFileSync(join(__dirname, '../.next/BUILD_ID'), 'utf8')
const res = await fetch(
`http://localhost:${appPort}/_next/static/${buildId}/pages/index.js`,
{
method: 'GET',
headers: {
'if-unmodified-since': 'Fri, 12 Jul 2019 20:00:13 GMT'
}
}
)
expect(res.status).toBe(412)
})
it('should set Content-Length header', async () => {
const url = `http://localhost:${appPort}`
const res = await fetch(url)