summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorAliaksandr Kalenik <kalenik.aliaksandr@gmail.com>2023-04-14 20:42:12 +0300
committerLinus Groh <mail@linusgroh.de>2023-04-24 13:38:37 +0100
commit269c25e1d2453b34bffceaa8ce5c81474992fc53 (patch)
tree0e35f09cfc72ca5df06e8c271a01038d6e557197 /Userland/Libraries/LibWeb
parent7b6cea9ef4d3e568115b8081263c8b9aad798616 (diff)
downloadserenity-269c25e1d2453b34bffceaa8ce5c81474992fc53.zip
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
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp24
-rw-r--r--Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.h2
2 files changed, 19 insertions, 7 deletions
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<JS::NonnullGCPtr<PendingResponse>> http_fetch(JS::Realm& rea
return;
}
- JS::GCPtr<PendingResponse> inner_pending_response;
+ Optional<JS::NonnullGCPtr<PendingResponse>> 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<JS::NonnullGCPtr<PendingResponse>> http_fetch(JS::Realm& rea
}
}
- if (inner_pending_response) {
- inner_pending_response->when_loaded([returned_pending_response](JS::NonnullGCPtr<Infrastructure::Response> response) {
+ if (inner_pending_response.has_value()) {
+ inner_pending_response.value()->when_loaded([returned_pending_response](JS::NonnullGCPtr<Infrastructure::Response> 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<JS::NonnullGCPtr<PendingResponse>> http_fetch(JS::Realm& rea
}
// https://fetch.spec.whatwg.org/#concept-http-redirect-fetch
-WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_redirect_fetch(JS::Realm& realm, Infrastructure::FetchParams const& fetch_params, Infrastructure::Response& response)
+WebIDL::ExceptionOr<Optional<JS::NonnullGCPtr<PendingResponse>>> 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<JS::NonnullGCPtr<PendingResponse>> 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<Optional<JS::NonnullGCPtr<PendingResponse>>> main_fetch(JS::
WebIDL::ExceptionOr<void> fetch_response_handover(JS::Realm&, Infrastructure::FetchParams const&, Infrastructure::Response&);
WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> scheme_fetch(JS::Realm&, Infrastructure::FetchParams const&);
WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_fetch(JS::Realm&, Infrastructure::FetchParams const&, MakeCORSPreflight make_cors_preflight = MakeCORSPreflight::No);
-WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_redirect_fetch(JS::Realm&, Infrastructure::FetchParams const&, Infrastructure::Response&);
+WebIDL::ExceptionOr<Optional<JS::NonnullGCPtr<PendingResponse>>> http_redirect_fetch(JS::Realm&, Infrastructure::FetchParams const&, Infrastructure::Response&);
WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> 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<JS::NonnullGCPtr<PendingResponse>> 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<JS::NonnullGCPtr<PendingResponse>> cors_preflight_fetch(JS::Realm&, Infrastructure::Request&);