fix(next/image): bypass icns images (#65414)

Closes NEXT-3329
This commit is contained in:
Steven 2024-05-06 15:01:14 -04:00 committed by GitHub
parent aa1e9676f1
commit 44a21f4cc2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 38 additions and 0 deletions

View file

@ -5,6 +5,7 @@ import send from 'next/dist/compiled/send'
// Although "mime" has already add avif in version 2.4.7, "send" is still using mime@1.6.0
send.mime.define({
'image/avif': ['avif'],
'image/x-icns': ['icns'],
})
export function serveStatic(

Binary file not shown.

Binary file not shown.

View file

@ -174,6 +174,43 @@ export function runTests(ctx) {
expect(res.status).toBe(200)
})
it('should maintain icns', async () => {
const query = { w: ctx.w, q: 90, url: '/test.icns' }
const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, {})
expect(res.status).toBe(200)
expect(res.headers.get('Content-Type')).toContain('image/x-icns')
expect(res.headers.get('Cache-Control')).toBe(
`public, max-age=${isDev ? 0 : minimumCacheTTL}, must-revalidate`
)
expect(res.headers.get('Vary')).toBe('Accept')
expect(res.headers.get('etag')).toBeTruthy()
expect(res.headers.get('Content-Disposition')).toBe(
`${contentDispositionType}; filename="test.icns"`
)
await expectWidth(res, 256)
})
it('should maintain pic/pct', async () => {
const query = { w: ctx.w, q: 90, url: '/test.pic' }
const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, {})
expect(res.status).toBe(200)
expect(res.headers.get('Content-Type')).toContain('image/x-pict')
expect(res.headers.get('Cache-Control')).toBe(
`public, max-age=${isDev ? 0 : minimumCacheTTL}, must-revalidate`
)
expect(res.headers.get('Vary')).toBe('Accept')
expect(res.headers.get('etag')).toBeTruthy()
expect(res.headers.get('Content-Disposition')).toBe(
`${contentDispositionType}; filename="test.pic"`
)
const actual = await res.text()
const expected = await fs.readFile(
join(ctx.appDir, 'public', 'test.pic'),
'utf8'
)
expect(actual).toMatch(expected)
})
it('should maintain animated gif', async () => {
const query = { w: ctx.w, q: 90, url: '/animated.gif' }
const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, {})