From 269c25e1d2453b34bffceaa8ce5c81474992fc53 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Fri, 14 Apr 2023 20:42:12 +0300 Subject: LibWeb/Fetch: Pass recursive=false to manual navigation redirect Implement https://github.com/whatwg/fetch/commit/ca10f49748f2289433ce75dcf1f2fcf451f4f24f Fixes the issue I found while working on navigation: https://github.com/whatwg/fetch/issues/1629 --- .../Libraries/LibWeb/Fetch/Fetching/Fetching.cpp | 24 ++++++++++++++++------ .../Libraries/LibWeb/Fetch/Fetching/Fetching.h | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'Userland/Libraries/LibWeb') diff --git a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index a4be68d3a3..d1d5daa718 100644 --- a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -923,7 +923,7 @@ WebIDL::ExceptionOr> http_fetch(JS::Realm& rea return; } - JS::GCPtr inner_pending_response; + Optional> inner_pending_response; // 7. If actualResponse’s status is a redirect status, then: if (Infrastructure::is_redirect_status(actual_response->status())) { @@ -963,8 +963,8 @@ WebIDL::ExceptionOr> http_fetch(JS::Realm& rea } } - if (inner_pending_response) { - inner_pending_response->when_loaded([returned_pending_response](JS::NonnullGCPtr response) { + if (inner_pending_response.has_value()) { + inner_pending_response.value()->when_loaded([returned_pending_response](JS::NonnullGCPtr response) { dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'HTTP fetch' inner_pending_response load callback"); returned_pending_response->resolve(response); }); @@ -979,7 +979,7 @@ WebIDL::ExceptionOr> http_fetch(JS::Realm& rea } // https://fetch.spec.whatwg.org/#concept-http-redirect-fetch -WebIDL::ExceptionOr> http_redirect_fetch(JS::Realm& realm, Infrastructure::FetchParams const& fetch_params, Infrastructure::Response& response) +WebIDL::ExceptionOr>> http_redirect_fetch(JS::Realm& realm, Infrastructure::FetchParams const& fetch_params, Infrastructure::Response& response) { dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'HTTP-redirect fetch' with: fetch_params @ {}, response = {}", &fetch_params, &response); @@ -1108,8 +1108,20 @@ WebIDL::ExceptionOr> http_redirect_fetch(JS::R // FIXME: 19. Invoke set request’s referrer policy on redirect on request and actualResponse. - // 20. Return the result of running main fetch given fetchParams and true. - return TRY(main_fetch(realm, fetch_params, Recursive::Yes)).release_value(); + // 20. Let recursive be true. + auto recursive = Recursive::Yes; + + // 21. If request’s redirect mode is "manual", then: + if (request->redirect_mode() == Infrastructure::Request::RedirectMode::Manual) { + // 1. Assert: request’s mode is "navigate". + VERIFY(request->mode() == Infrastructure::Request::Mode::Navigate); + + // 2. Set recursive to false. + recursive = Recursive::No; + } + + // 22. Return the result of running main fetch given fetchParams and recursive. + return main_fetch(realm, fetch_params, recursive); } // https://fetch.spec.whatwg.org/#concept-http-network-or-cache-fetch diff --git a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.h b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.h index e1c88aeccb..76373ad17a 100644 --- a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.h +++ b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.h @@ -34,7 +34,7 @@ WebIDL::ExceptionOr>> main_fetch(JS:: WebIDL::ExceptionOr fetch_response_handover(JS::Realm&, Infrastructure::FetchParams const&, Infrastructure::Response&); WebIDL::ExceptionOr> scheme_fetch(JS::Realm&, Infrastructure::FetchParams const&); WebIDL::ExceptionOr> http_fetch(JS::Realm&, Infrastructure::FetchParams const&, MakeCORSPreflight make_cors_preflight = MakeCORSPreflight::No); -WebIDL::ExceptionOr> http_redirect_fetch(JS::Realm&, Infrastructure::FetchParams const&, Infrastructure::Response&); +WebIDL::ExceptionOr>> http_redirect_fetch(JS::Realm&, Infrastructure::FetchParams const&, Infrastructure::Response&); WebIDL::ExceptionOr> http_network_or_cache_fetch(JS::Realm&, Infrastructure::FetchParams const&, IsAuthenticationFetch is_authentication_fetch = IsAuthenticationFetch::No, IsNewConnectionFetch is_new_connection_fetch = IsNewConnectionFetch::No); WebIDL::ExceptionOr> nonstandard_resource_loader_file_or_http_network_fetch(JS::Realm&, Infrastructure::FetchParams const&, IncludeCredentials include_credentials = IncludeCredentials::No, IsNewConnectionFetch is_new_connection_fetch = IsNewConnectionFetch::No); WebIDL::ExceptionOr> cors_preflight_fetch(JS::Realm&, Infrastructure::Request&); -- cgit v1.2.3