Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/next/src/server/image-optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const PNG = 'image/png'
const JPEG = 'image/jpeg'
const GIF = 'image/gif'
const SVG = 'image/svg+xml'
const ICO = 'image/x-icon'
const CACHE_VERSION = 3
const ANIMATABLE_TYPES = [WEBP, PNG, GIF]
const VECTOR_TYPES = [SVG]
Expand Down Expand Up @@ -141,6 +142,9 @@ export function detectContentType(buffer: Buffer) {
) {
return AVIF
}
if ([0x00, 0x00, 0x01, 0x00].every((b, i) => buffer[i] === b)) {
return ICO
}
styfle marked this conversation as resolved.
Show resolved Hide resolved
return null
}

Expand Down
4 changes: 4 additions & 0 deletions test/unit/image-optimizer/detect-content-type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ describe('detectContentType', () => {
const buffer = await getImage('./images/test.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')
})
})
Binary file added test/unit/image-optimizer/images/test.ico
Binary file not shown.