|
@@ -78,19 +78,21 @@ ErrorOr<Optional<AK::URL>> Response::location_url(Optional<String> const& reques
|
|
|
}
|
|
|
|
|
|
// https://fetch.spec.whatwg.org/#concept-response-clone
|
|
|
-NonnullOwnPtr<Response> Response::clone() const
|
|
|
+WebIDL::ExceptionOr<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.
|
|
|
+ Optional<Body> tmp_body;
|
|
|
+ swap(tmp_body, const_cast<Optional<Body>&>(m_body));
|
|
|
+ auto new_response = make<Infrastructure::Response>(*this);
|
|
|
+ swap(tmp_body, const_cast<Optional<Body>&>(m_body));
|
|
|
+
|
|
|
+ // 3. If response’s body is non-null, then set newResponse’s body to the result of cloning response’s body.
|
|
|
+ if (m_body.has_value())
|
|
|
+ new_response->set_body(TRY(m_body->clone()));
|
|
|
|
|
|
// 4. Return newResponse.
|
|
|
return new_response;
|