LibWeb: Update steps of HTTP-network-or-cache-fetch per the latest spec

One step was added since we last visited this AO.
This commit is contained in:
Andrew Kaster 2024-05-21 09:17:23 -06:00 committed by Tim Flynn
commit a40b331f39
Notes: sideshowbarker 2024-07-17 10:31:19 +09:00

View file

@ -1394,7 +1394,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet
// 13. Append the Fetch metadata headers for httpRequest.
append_fetch_metadata_headers_for_request(*http_request);
// 14. If httpRequests header list does not contain `User-Agent`, then user agents should append
// 14. FIXME If httpRequests initiator is "prefetch", then set a structured field value
// given (`Sec-Purpose`, the token prefetch) in httpRequests header list.
// 15. If httpRequests header list does not contain `User-Agent`, then user agents should append
// (`User-Agent`, default `User-Agent` value) to httpRequests header list.
if (!http_request->header_list()->contains("User-Agent"sv.bytes())) {
auto header = Infrastructure::Header {
@ -1404,7 +1407,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet
http_request->header_list()->append(move(header));
}
// 15. If httpRequests cache mode is "default" and httpRequests header list contains `If-Modified-Since`,
// 16. If httpRequests cache mode is "default" and httpRequests header list contains `If-Modified-Since`,
// `If-None-Match`, `If-Unmodified-Since`, `If-Match`, or `If-Range`, then set httpRequests cache mode to
// "no-store".
if (http_request->cache_mode() == Infrastructure::Request::CacheMode::Default
@ -1416,7 +1419,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet
http_request->set_cache_mode(Infrastructure::Request::CacheMode::NoStore);
}
// 16. If httpRequests cache mode is "no-cache", httpRequests prevent no-cache cache-control header
// 17. If httpRequests cache mode is "no-cache", httpRequests prevent no-cache cache-control header
// modification flag is unset, and httpRequests header list does not contain `Cache-Control`, then append
// (`Cache-Control`, `max-age=0`) to httpRequests header list.
if (http_request->cache_mode() == Infrastructure::Request::CacheMode::NoCache
@ -1426,7 +1429,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet
http_request->header_list()->append(move(header));
}
// 17. If httpRequests cache mode is "no-store" or "reload", then:
// 18. If httpRequests cache mode is "no-store" or "reload", then:
if (http_request->cache_mode() == Infrastructure::Request::CacheMode::NoStore
|| http_request->cache_mode() == Infrastructure::Request::CacheMode::Reload) {
// 1. If httpRequests header list does not contain `Pragma`, then append (`Pragma`, `no-cache`) to
@ -1444,7 +1447,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet
}
}
// 18. If httpRequests header list contains `Range`, then append (`Accept-Encoding`, `identity`) to
// 19. If httpRequests header list contains `Range`, then append (`Accept-Encoding`, `identity`) to
// httpRequests header list.
// NOTE: This avoids a failure when handling content codings with a part of an encoded response.
// Additionally, many servers mistakenly ignore `Range` headers if a non-identity encoding is accepted.
@ -1453,7 +1456,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet
http_request->header_list()->append(move(header));
}
// 19. Modify httpRequests header list per HTTP. Do not append a given header if httpRequests header list
// 20. Modify httpRequests header list per HTTP. Do not append a given header if httpRequests header list
// contains that headers name.
// NOTE: It would be great if we could make this more normative somehow. At this point headers such as
// `Accept-Encoding`, `Connection`, `DNT`, and `Host`, are to be appended if necessary.
@ -1462,7 +1465,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet
// the latter by default), and `Accept-Charset` is a waste of bytes. See HTTP header layer division for
// more details.
// 20. If includeCredentials is true, then:
// 21. If includeCredentials is true, then:
if (include_credentials == IncludeCredentials::Yes) {
// 1. If the user agent is not configured to block cookies for httpRequest (see section 7 of [COOKIES]),
// then:
@ -1513,16 +1516,16 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet
}
}
// FIXME: 21. If theres a proxy-authentication entry, use it as appropriate.
// FIXME: 22. If theres a proxy-authentication entry, use it as appropriate.
// NOTE: This intentionally does not depend on httpRequests credentials mode.
// FIXME: 22. Set httpCache to the result of determining the HTTP cache partition, given httpRequest.
// FIXME: 23. Set httpCache to the result of determining the HTTP cache partition, given httpRequest.
// 23. If httpCache is null, then set httpRequests cache mode to "no-store".
// 24. If httpCache is null, then set httpRequests cache mode to "no-store".
if (!http_cache)
http_request->set_cache_mode(Infrastructure::Request::CacheMode::NoStore);
// 24. If httpRequests cache mode is neither "no-store" nor "reload", then:
// 25. If httpRequests cache mode is neither "no-store" nor "reload", then:
if (http_request->cache_mode() != Infrastructure::Request::CacheMode::NoStore
&& http_request->cache_mode() != Infrastructure::Request::CacheMode::Reload) {
// 1. Set storedResponse to the result of selecting a response from the httpCache, possibly needing