mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:37:44 +00:00
LibWeb: Implement Fetch::Infrastructure::Response::clone()
This commit is contained in:
parent
b5e8e9b30b
commit
ef5e2eb794
2 changed files with 22 additions and 0 deletions
|
@ -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 response’s 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 response’s body is non-null, then set newResponse’s body to the result of cloning response’s body.
|
||||
|
||||
// 4. Return newResponse.
|
||||
return new_response;
|
||||
}
|
||||
|
||||
FilteredResponse::FilteredResponse(Response& internal_response)
|
||||
: m_internal_response(internal_response)
|
||||
{
|
||||
|
|
|
@ -100,6 +100,8 @@ public:
|
|||
[[nodiscard]] Optional<AK::URL const&> url() const;
|
||||
[[nodiscard]] ErrorOr<Optional<AK::URL>> location_url(Optional<String> const& request_fragment) const;
|
||||
|
||||
[[nodiscard]] NonnullOwnPtr<Response> clone() const;
|
||||
|
||||
private:
|
||||
// https://fetch.spec.whatwg.org/#concept-response-type
|
||||
// A response has an associated type which is "basic", "cors", "default", "error", "opaque", or "opaqueredirect". Unless stated otherwise, it is "default".
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue