Unverified Commit 74891fde authored by Maksym Anisimov's avatar Maksym Anisimov Committed by GitHub

Add auto-detection of image/x-icon content type (#47013)

Added auto-detection of image/x-icon content type by analyzing response buffer

fixes https://github.com/vercel/next.js/discussions/45998Co-authored-by: 's avatarSteven <229881+styfle@users.noreply.github.com>
parent 84104af6
...@@ -33,6 +33,7 @@ const PNG = 'image/png' ...@@ -33,6 +33,7 @@ const PNG = 'image/png'
const JPEG = 'image/jpeg' const JPEG = 'image/jpeg'
const GIF = 'image/gif' const GIF = 'image/gif'
const SVG = 'image/svg+xml' const SVG = 'image/svg+xml'
const ICO = 'image/x-icon'
const CACHE_VERSION = 3 const CACHE_VERSION = 3
const ANIMATABLE_TYPES = [WEBP, PNG, GIF] const ANIMATABLE_TYPES = [WEBP, PNG, GIF]
const VECTOR_TYPES = [SVG] const VECTOR_TYPES = [SVG]
...@@ -141,6 +142,9 @@ export function detectContentType(buffer: Buffer) { ...@@ -141,6 +142,9 @@ export function detectContentType(buffer: Buffer) {
) { ) {
return AVIF return AVIF
} }
if ([0x00, 0x00, 0x01, 0x00].every((b, i) => buffer[i] === b)) {
return ICO
}
return null return null
} }
......
...@@ -26,4 +26,8 @@ describe('detectContentType', () => { ...@@ -26,4 +26,8 @@ describe('detectContentType', () => {
const buffer = await getImage('./images/test.avif') const buffer = await getImage('./images/test.avif')
expect(detectContentType(buffer)).toBe('image/avif') expect(detectContentType(buffer)).toBe('image/avif')
}) })
it('should return icon', async () => {
const buffer = await getImage('./images/test.ico')
expect(detectContentType(buffer)).toBe('image/x-icon')
})
}) })
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