LibWeb/Fetch: Use correct header for prefetch requests

See:
 - https://github.com/whatwg/fetch/commit/a5560d2
This commit is contained in:
Jamie Mansfield 2024-07-12 20:01:10 +01:00 committed by Andreas Kling
parent aee77b975c
commit 9ce727d315
Notes: sideshowbarker 2024-07-16 20:12:13 +09:00
2 changed files with 14 additions and 6 deletions

View File

@ -189,9 +189,13 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Infrastructure::FetchController>> fetch(JS:
// 1. Let value be `*/*`.
auto value = "*/*"sv;
// 2. A user agent should set value to the first matching statement, if any, switching on requests
// destination:
if (request.destination().has_value()) {
// 2. If requests initiator is "prefetch", then set value to the document `Accept` header value.
if (request.initiator() == Infrastructure::Request::Initiator::Prefetch) {
value = document_accept_header_value;
}
// 3. Otherwise, the user agent should set value to the first matching statement, if any, switching on requests destination:
else if (request.destination().has_value()) {
switch (*request.destination()) {
// -> "document"
// -> "frame"
@ -199,8 +203,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Infrastructure::FetchController>> fetch(JS:
case Infrastructure::Request::Destination::Document:
case Infrastructure::Request::Destination::Frame:
case Infrastructure::Request::Destination::IFrame:
// `text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8`
value = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"sv;
// the document `Accept` header value
value = document_accept_header_value;
break;
// -> "image"
case Infrastructure::Request::Destination::Image:
@ -222,7 +226,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Infrastructure::FetchController>> fetch(JS:
}
}
// 3. Append (`Accept`, value) to requests header list.
// 4. Append (`Accept`, value) to requests header list.
auto header = Infrastructure::Header::from_string_pair("Accept"sv, value.bytes());
request.header_list()->append(move(header));
}

View File

@ -14,6 +14,10 @@
namespace Web::Fetch::Fetching {
// https://fetch.spec.whatwg.org/#document-accept-header-value
// The document `Accept` header value is `text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8`.
constexpr auto document_accept_header_value = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"sv;
#define ENUMERATE_BOOL_PARAMS \
__ENUMERATE_BOOL_PARAM(IncludeCredentials) \
__ENUMERATE_BOOL_PARAM(IsAuthenticationFetch) \