diff --git a/devtools/client/netmonitor/test/browser_net_copy_headers.js b/devtools/client/netmonitor/test/browser_net_copy_headers.js index f82ccfcc8a9f..e5bd2bfee251 100644 --- a/devtools/client/netmonitor/test/browser_net_copy_headers.js +++ b/devtools/client/netmonitor/test/browser_net_copy_headers.js @@ -42,7 +42,7 @@ add_task(async function () { `${method} ${SIMPLE_URL.split("example.com")[1]} ${httpVersion}`, "Host: example.com", "User-Agent: " + navigator.userAgent + "", - "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8", + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8", "Accept-Language: " + navigator.languages.join(",") + ";q=0.5", "Accept-Encoding: gzip, deflate", "Connection: keep-alive", diff --git a/dom/tests/browser/browser_persist_image_accept.js b/dom/tests/browser/browser_persist_image_accept.js index 24675a4469b7..21a2096b9dea 100644 --- a/dom/tests/browser/browser_persist_image_accept.js +++ b/dom/tests/browser/browser_persist_image_accept.js @@ -51,7 +51,7 @@ function expectedImageAcceptHeader() { return ( (Services.prefs.getBoolPref("image.avif.enabled") ? "image/avif," : "") + (Services.prefs.getBoolPref("image.jxl.enabled") ? "image/jxl," : "") + - "image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5" + "image/webp,*/*" ); } diff --git a/image/test/mochitest/bug496292-1.sjs b/image/test/mochitest/bug496292-1.sjs index f10de708e4c5..2e842223d551 100644 --- a/image/test/mochitest/bug496292-1.sjs +++ b/image/test/mochitest/bug496292-1.sjs @@ -6,10 +6,7 @@ function handleRequest(request, response) { file.append("test"); file.append("mochitest"); - if ( - request.getHeader("Accept") == - "image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5" - ) { + if (request.getHeader("Accept") == "image/avif,image/webp,*/*") { file.append("blue.png"); } else { file.append("red.png"); diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index 068926844af7..782f2893ff12 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -216,33 +216,17 @@ static nsCString ImageAcceptHeader() { mimeTypes.Append("image/jxl,"); } - mimeTypes.Append("image/webp,"); - - // Default value as specified by fetch standard - // https://fetch.spec.whatwg.org/commit-snapshots/8dd73dbecfefdbef8f432164fb3a5b9785f7f520/#ref-for-header-list-contains%E2%91%A7 - mimeTypes.Append("image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"); + mimeTypes.Append("image/webp,*/*"); return mimeTypes; } -static nsCString DocumentAcceptHeader() { - // https://fetch.spec.whatwg.org/#document-accept-header-value - // The value specified by the fetch standard is - // `text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8` - // but we also insert all of the image formats before */* - nsCString mimeTypes("text/html,application/xhtml+xml,application/xml;q=0.9,"); +static nsCString DocumentAcceptHeader(const nsCString& aImageAcceptHeader) { + nsPrintfCString mimeTypes( + "text/html,application/xhtml+xml,application/xml;q=0.9,%s;q=0.8", + aImageAcceptHeader.get()); - if (mozilla::StaticPrefs::image_avif_enabled()) { - mimeTypes.Append("image/avif,"); - } - - if (mozilla::StaticPrefs::image_jxl_enabled()) { - mimeTypes.Append("image/jxl,"); - } - - mimeTypes.Append("image/webp,image/png,image/svg+xml,*/*;q=0.8"); - - return mimeTypes; + return std::move(mimeTypes); } nsHttpHandler::nsHttpHandler() @@ -251,7 +235,7 @@ nsHttpHandler::nsHttpHandler() PR_SecondsToInterval(StaticPrefs::network_http_http2_timeout())), mResponseTimeout(PR_SecondsToInterval(300)), mImageAcceptHeader(ImageAcceptHeader()), - mDocumentAcceptHeader(DocumentAcceptHeader()), + mDocumentAcceptHeader(DocumentAcceptHeader(ImageAcceptHeader())), mLastUniqueID(NowInSeconds()), mDebugObservations(false), mEnableAltSvc(false), @@ -1763,7 +1747,7 @@ void nsHttpHandler::PrefsChanged(const char* pref) { } if (userSetDocumentAcceptHeader.IsEmpty()) { - mDocumentAcceptHeader.Assign(DocumentAcceptHeader()); + mDocumentAcceptHeader.Assign(DocumentAcceptHeader(mImageAcceptHeader)); } else { mDocumentAcceptHeader.Assign(userSetDocumentAcceptHeader); } diff --git a/netwerk/test/mochitests/test_accept_header.html b/netwerk/test/mochitests/test_accept_header.html index 977c531dcffc..0acae2a825bb 100644 --- a/netwerk/test/mochitests/test_accept_header.html +++ b/netwerk/test/mochitests/test_accept_header.html @@ -26,7 +26,7 @@ function test_iframe() { let ifr = document.createElement("iframe"); ifr.src = "test_accept_header.sjs?iframe"; ifr.onload = () => { - test_last_request_and_continue("iframe", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8"); + test_last_request_and_continue("iframe", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"); }; document.body.appendChild(ifr); } @@ -36,7 +36,7 @@ function test_image() { i.src = "test_accept_header.sjs?image"; i.onload = function() { // Fetch spec says we should have: "image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5" - test_last_request_and_continue("image", "image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"); + test_last_request_and_continue("image", "image/avif,image/webp,*/*"); } }