From 8542a8b458a4efe56a150074db37f7a8086d5d09 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Wed, 5 Jun 2024 19:36:18 +0100 Subject: [PATCH] LibWeb/Fetch: Update "HTTP-redirect fetch" algorithm to latest spec The spec and implementation's comments had diverged a little, this brings them in line :) --- .../LibWeb/Fetch/Fetching/Fetching.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index 4a0711d23ca..b98391263c0 100644 --- a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -1120,14 +1120,14 @@ WebIDL::ExceptionOr> http_redirect_fetch(JS::Realm& r // 1. Let request be fetchParams’s request. auto request = fetch_params.request(); - // 2. Let actualResponse be response, if response is not a filtered response, and response’s internal response - // otherwise. - auto actual_response = !is(response) + // 2. Let internalResponse be response, if response is not a filtered response; otherwise response’s internal + // response. + auto internal_response = !is(response) ? JS::NonnullGCPtr { response } : static_cast(response).internal_response(); - // 3. Let locationURL be actualResponse’s location URL given request’s current URL’s fragment. - auto location_url_or_error = actual_response->location_url(request->current_url().fragment()); + // 3. Let locationURL be internalResponse’s location URL given request’s current URL’s fragment. + auto location_url_or_error = internal_response->location_url(request->current_url().fragment()); // 4. If locationURL is null, then return response. if (!location_url_or_error.is_error() && !location_url_or_error.value().has_value()) @@ -1150,7 +1150,7 @@ WebIDL::ExceptionOr> http_redirect_fetch(JS::Realm& r // 8. Increase request’s redirect count by 1. request->set_redirect_count(request->redirect_count() + 1); - // 8. If request’s mode is "cors", locationURL includes credentials, and request’s origin is not same origin with + // 9. If request’s mode is "cors", locationURL includes credentials, and request’s origin is not same origin with // locationURL’s origin, then return a network error. if (request->mode() == Infrastructure::Request::Mode::CORS && location_url.includes_credentials() @@ -1164,9 +1164,9 @@ WebIDL::ExceptionOr> http_redirect_fetch(JS::Realm& r if (request->response_tainting() == Infrastructure::Request::ResponseTainting::CORS && location_url.includes_credentials()) return PendingResponse::create(vm, request, Infrastructure::Response::network_error(vm, "Request with 'cors' response tainting must not include credentials in redirect URL"sv)); - // 11. If actualResponse’s status is not 303, request’s body is non-null, and request’s body’s source is null, then + // 11. If internalResponse’s status is not 303, request’s body is non-null, and request’s body’s source is null, then // return a network error. - if (actual_response->status() != 303 + if (internal_response->status() != 303 && !request->body().has() && request->body().get>()->source().has()) { return PendingResponse::create(vm, request, Infrastructure::Response::network_error(vm, "Request has body but no body source"sv)); @@ -1174,10 +1174,10 @@ WebIDL::ExceptionOr> http_redirect_fetch(JS::Realm& r // 12. If one of the following is true if ( - // - actualResponse’s status is 301 or 302 and request’s method is `POST` - ((actual_response->status() == 301 || actual_response->status() == 302) && request->method() == "POST"sv.bytes()) - // - actualResponse’s status is 303 and request’s method is not `GET` or `HEAD` - || (actual_response->status() == 303 && !(request->method() == "GET"sv.bytes() || request->method() == "HEAD"sv.bytes())) + // - internalResponse’s status is 301 or 302 and request’s method is `POST` + ((internal_response->status() == 301 || internal_response->status() == 302) && request->method() == "POST"sv.bytes()) + // - internalResponse’s status is 303 and request’s method is not `GET` or `HEAD` + || (internal_response->status() == 303 && !(request->method() == "GET"sv.bytes() || request->method() == "HEAD"sv.bytes())) // then: ) { // 1. Set request’s method to `GET` and request’s body to null. @@ -1236,7 +1236,7 @@ WebIDL::ExceptionOr> http_redirect_fetch(JS::Realm& r // 18. Append locationURL to request’s URL list. request->url_list().append(location_url); - // FIXME: 19. Invoke set request’s referrer policy on redirect on request and actualResponse. + // FIXME: 19. Invoke set request’s referrer policy on redirect on request and internalResponse. // 20. Let recursive be true. auto recursive = Recursive::Yes;