1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 21:08:12 +00:00

LibWeb: Implement Fetch::Infrastructure::Response::clone()

This commit is contained in:
Linus Groh 2022-09-25 19:23:35 +01:00
parent b5e8e9b30b
commit ef5e2eb794
2 changed files with 22 additions and 0 deletions

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
namespace Web::Fetch::Infrastructure {
@ -76,6 +77,25 @@ ErrorOr<Optional<AK::URL>> Response::location_url(Optional<String> const& reques
return location;
}
// https://fetch.spec.whatwg.org/#concept-response-clone
NonnullOwnPtr<Response> 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 responses internal response.
// 2. Let newResponse be a copy of response, except for its body.
Optional<Body> body;
swap(body, const_cast<Optional<Body>&>(m_body));
auto new_response = adopt_own(*new Infrastructure::Response(*this));
swap(body, const_cast<Optional<Body>&>(m_body));
// FIXME: 3. If responses body is non-null, then set newResponses body to the result of cloning responses body.
// 4. Return newResponse.
return new_response;
}
FilteredResponse::FilteredResponse(Response& internal_response)
: m_internal_response(internal_response)
{