LibWeb/Fetch: Pass recursive=false to manual navigation redirect

Implement ca10f49748

Fixes the issue I found while working on navigation:
https://github.com/whatwg/fetch/issues/1629
This commit is contained in:
Aliaksandr Kalenik 2023-04-14 20:42:12 +03:00 committed by Linus Groh
parent 7b6cea9ef4
commit 269c25e1d2
Notes: sideshowbarker 2024-07-16 22:58:46 +09:00
2 changed files with 19 additions and 7 deletions

View file

@ -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 actualResponses 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 requests 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 requests redirect mode is "manual", then:
if (request->redirect_mode() == Infrastructure::Request::RedirectMode::Manual) {
// 1. Assert: requests 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