Skip to content

Commit e984e8f

Browse files
vicbsommeeeer
andauthored
fallback to the content-type header (#781)
Co-authored-by: Magnus Dahl Eide <magnus@dahleide.com>
1 parent 224a2f0 commit e984e8f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

.changeset/short-knives-camp.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
fallback to the upstream image content-type header

packages/cloudflare/src/cli/templates/images.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ export async function fetchImage(fetcher: Fetcher | undefined, imageUrl: string,
9292
contentType = detectContentType(value);
9393
}
9494

95+
if (!contentType) {
96+
// Fallback to the sanitized upstream header when the type can not be detected
97+
// https://github.com/vercel/next.js/blob/d76f0b1/packages/next/src/server/image-optimizer.ts#L748
98+
const header = imgResponse.headers.get("content-type") ?? "";
99+
if (header.startsWith("image/") && !header.includes(",")) {
100+
contentType = header;
101+
}
102+
}
103+
95104
if (contentType && !(contentType === SVG && !__IMAGES_ALLOW_SVG__)) {
96105
const headers = new Headers(imgResponse.headers);
97106
headers.set("content-type", contentType);

0 commit comments

Comments
 (0)