LibWeb/Fetch: Use "json" destination

See:
- da8d0d8
- 49bff76
- 37659e9
This commit is contained in:
Jamie Mansfield 2024-05-03 20:44:06 +01:00 committed by Andrew Kaster
commit 987198782c
Notes: sideshowbarker 2024-07-17 16:23:06 +09:00
5 changed files with 18 additions and 8 deletions

View file

@ -160,6 +160,8 @@ Bindings::RequestDestination to_bindings_enum(Optional<Infrastructure::Request::
return Bindings::RequestDestination::Iframe;
case Infrastructure::Request::Destination::Image:
return Bindings::RequestDestination::Image;
case Infrastructure::Request::Destination::JSON:
return Bindings::RequestDestination::Json;
case Infrastructure::Request::Destination::Manifest:
return Bindings::RequestDestination::Manifest;
case Infrastructure::Request::Destination::Object:

View file

@ -165,6 +165,11 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Infrastructure::FetchController>> fetch(JS:
// `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;
break;
// -> "json"
case Infrastructure::Request::Destination::JSON:
// `application/json,*/*;q=0.5`
value = "application/json,*/*;q=0.5"sv;
break;
// -> "style"
case Infrastructure::Request::Destination::Style:
// `text/css,*/*;q=0.1`

View file

@ -99,12 +99,13 @@ bool Request::destination_is_script_like() const
// https://fetch.spec.whatwg.org/#subresource-request
bool Request::is_subresource_request() const
{
// A subresource request is a request whose destination is "audio", "audioworklet", "font", "image", "manifest", "paintworklet", "script", "style", "track", "video", "xslt", or the empty string.
// A subresource request is a request whose destination is "audio", "audioworklet", "font", "image", "json", "manifest", "paintworklet", "script", "style", "track", "video", "xslt", or the empty string.
static constexpr Array subresource_request_destinations = {
Destination::Audio,
Destination::AudioWorklet,
Destination::Font,
Destination::Image,
Destination::JSON,
Destination::Manifest,
Destination::PaintWorklet,
Destination::Script,

View file

@ -49,7 +49,7 @@ dictionary RequestInit {
any window; // can only be set to null
};
enum RequestDestination { "", "audio", "audioworklet", "document", "embed", "font", "frame", "iframe", "image", "manifest", "object", "paintworklet", "report", "script", "sharedworker", "style", "track", "video", "worker", "xslt" };
enum RequestDestination { "", "audio", "audioworklet", "document", "embed", "font", "frame", "iframe", "image", "json", "manifest", "object", "paintworklet", "report", "script", "sharedworker", "style", "track", "video", "worker", "xslt" };
enum RequestMode { "navigate", "same-origin", "no-cors", "cors" };
enum RequestCredentials { "omit", "same-origin", "include" };
enum RequestCache { "default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached" };

View file

@ -661,25 +661,27 @@ void fetch_single_module_script(JS::Realm& realm,
// 7. Set moduleMap[(url, moduleType)] to "fetching".
module_map.set(url, module_type, { ModuleMap::EntryType::Fetching, nullptr });
// 8. Let request be a new request whose URL is url, destination is destination, mode is "cors", referrer is referrer, and client is fetchClient.
// 8. Let request be a new request whose URL is url, mode is "cors", referrer is referrer, and client is fetchClient.
auto request = Fetch::Infrastructure::Request::create(realm.vm());
request->set_url(url);
request->set_destination(destination);
request->set_mode(Fetch::Infrastructure::Request::Mode::CORS);
request->set_referrer(referrer);
request->set_client(&fetch_client);
// 9. If destination is "worker", "sharedworker", or "serviceworker", and isTopLevel is true, then set request's mode to "same-origin".
// 9. Set request's destination to the result of running the fetch destination from module type steps given destination and moduleType.
request->set_destination(fetch_destination_from_module_type(destination, module_type));
// 10. If destination is "worker", "sharedworker", or "serviceworker", and isTopLevel is true, then set request's mode to "same-origin".
if ((destination == Fetch::Infrastructure::Request::Destination::Worker || destination == Fetch::Infrastructure::Request::Destination::SharedWorker || destination == Fetch::Infrastructure::Request::Destination::ServiceWorker) && is_top_level == TopLevelModule::Yes)
request->set_mode(Fetch::Infrastructure::Request::Mode::SameOrigin);
// 10. Set request's initiator type to "script".
// 11. Set request's initiator type to "script".
request->set_initiator_type(Fetch::Infrastructure::Request::InitiatorType::Script);
// 11. Set up the module script request given request and options.
// 12. Set up the module script request given request and options.
set_up_module_script_request(request, options);
// 12. If performFetch was given, run performFetch with request, isTopLevel, and with processResponseConsumeBody as defined below.
// 13. If performFetch was given, run performFetch with request, isTopLevel, and with processResponseConsumeBody as defined below.
// Otherwise, fetch request with processResponseConsumeBody set to processResponseConsumeBody as defined below.
// In both cases, let processResponseConsumeBody given response response and null, failure, or a byte sequence bodyBytes be the following algorithm:
auto process_response_consume_body = [&module_map, url, module_type, &settings_object, on_complete](JS::NonnullGCPtr<Fetch::Infrastructure::Response> response, Fetch::Infrastructure::FetchAlgorithms::BodyBytes body_bytes) {