From 0a186cb460df7eb8f54b37cc5b5f2c0fbc947f7d Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 24 Oct 2022 18:46:27 +0100 Subject: LibWeb: Handle filtered response in Response::clone() --- .../LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'Userland/Libraries') diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp index bd4b6141b3..d523e35f69 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include @@ -92,7 +93,22 @@ WebIDL::ExceptionOr> Response::clone() const { // To clone a response response, run these steps: - // FIXME: 1. If response is a filtered response, then return a new identical filtered response whose internal response is a clone of response’s internal response. + auto& vm = Bindings::main_thread_vm(); + auto& realm = *vm.current_realm(); + + // 1. If response is a filtered response, then return a new identical filtered response whose internal response is a clone of response’s internal response. + if (is(*this)) { + auto internal_response = TRY(static_cast(*this).internal_response()->clone()); + if (is(*this)) + return TRY_OR_RETURN_OOM(realm, BasicFilteredResponse::create(move(internal_response))); + if (is(*this)) + return TRY_OR_RETURN_OOM(realm, CORSFilteredResponse::create(move(internal_response))); + if (is(*this)) + return OpaqueFilteredResponse::create(move(internal_response)); + if (is(*this)) + return OpaqueRedirectFilteredResponse::create(move(internal_response)); + VERIFY_NOT_REACHED(); + } // 2. Let newResponse be a copy of response, except for its body. auto new_response = Infrastructure::Response::create(); -- cgit v1.2.3