LibWeb: Add AVIF and WebP to the Accept header for images

This matches the behavior of other engines. Some CDNs that do content
negotiation will fall back to non alpha-preserving formats if these
values are not present.
This commit is contained in:
Tim Ledbetter
2026-04-23 01:15:04 +01:00
committed by Andreas Kling
parent 49834ef782
commit 59bf30f17f
Notes: github-actions[bot] 2026-04-25 06:50:12 +00:00
3 changed files with 37 additions and 1 deletions

View File

@@ -267,7 +267,10 @@ GC::Ref<Infrastructure::FetchController> fetch(JS::Realm& realm, Infrastructure:
// -> "image"
case Infrastructure::Request::Destination::Image:
// `image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5`
value = "image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"sv;
// AD-HOC: The spec default omits AVIF and WebP, which causes CDNs that perform format negotiation to
// potentially fall back to non alpha-preserving formats.
// Spec issue: https://github.com/whatwg/fetch/issues/1740
value = "image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"sv;
break;
// -> "json"
case Infrastructure::Request::Destination::JSON:

View File

@@ -0,0 +1 @@
image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5

View File

@@ -0,0 +1,32 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
promiseTest(async () => {
const httpServer = httpTestServer();
// A 1x1 transparent PNG.
const transparentPng = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
const url = await httpServer.createEcho("GET", "/image-accept-header-probe", {
status: 200,
headers: {
"Content-Type": "image/png",
},
body_encoding: "base64",
body: transparentPng,
});
const image = new Image();
await new Promise((resolve) => {
image.onload = resolve;
image.onerror = resolve;
image.src = url;
});
const echoUrl = new URL(url);
const response = await fetch(`${echoUrl.origin}/recorded-request-headers${echoUrl.pathname}`);
const headers = await response.json();
println(headers["Accept"][0]);
});
</script>