mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
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:
committed by
Andreas Kling
parent
49834ef782
commit
59bf30f17f
Notes:
github-actions[bot]
2026-04-25 06:50:12 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/59bf30f17fe Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/9046
@@ -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:
|
||||
|
||||
1
Tests/LibWeb/Text/expected/Fetch/image-accept-header.txt
Normal file
1
Tests/LibWeb/Text/expected/Fetch/image-accept-header.txt
Normal file
@@ -0,0 +1 @@
|
||||
image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5
|
||||
32
Tests/LibWeb/Text/input/Fetch/image-accept-header.html
Normal file
32
Tests/LibWeb/Text/input/Fetch/image-accept-header.html
Normal 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>
|
||||
Reference in New Issue
Block a user