Unverified Commit a79eb4fd authored by Steven's avatar Steven Committed by GitHub

Fix immutable header on static image (#25914)

This PR fixes a bug where the first request has the correct immutable header but subsequent requests do not.

Depends on #25909 
parent 50a36eec
...@@ -163,7 +163,12 @@ export async function imageOptimizer( ...@@ -163,7 +163,12 @@ export async function imageOptimizer(
const contentType = getContentType(extension) const contentType = getContentType(extension)
const fsPath = join(hashDir, file) const fsPath = join(hashDir, file)
if (now < expireAt) { if (now < expireAt) {
res.setHeader('Cache-Control', 'public, max-age=0, must-revalidate') res.setHeader(
'Cache-Control',
isStatic
? 'public, max-age=315360000, immutable'
: 'public, max-age=0, must-revalidate'
)
if (sendEtagResponse(req, res, etag)) { if (sendEtagResponse(req, res, etag)) {
return { finished: true } return { finished: true }
} }
......
...@@ -512,11 +512,21 @@ function runTests({ w, isDev, domains }) { ...@@ -512,11 +512,21 @@ function runTests({ w, isDev, domains }) {
q: 100, q: 100,
} }
const opts = { headers: { accept: 'image/webp' } } const opts = { headers: { accept: 'image/webp' } }
const res = await fetchViaHTTP(appPort, '/_next/image', query, opts)
expect(res.status).toBe(200) const res1 = await fetchViaHTTP(appPort, '/_next/image', query, opts)
expect(res.headers.get('cache-control')).toBe( expect(res1.status).toBe(200)
expect(res1.headers.get('cache-control')).toBe(
'public, max-age=315360000, immutable'
)
await expectWidth(res1, w)
// Ensure subsequent request also has immutable header
const res2 = await fetchViaHTTP(appPort, '/_next/image', query, opts)
expect(res2.status).toBe(200)
expect(res2.headers.get('cache-control')).toBe(
'public, max-age=315360000, immutable' 'public, max-age=315360000, immutable'
) )
await expectWidth(res2, w)
} }
}) })
......
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