mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
LibWeb: Stub out Fetch::Infrastructure::Body::clone()
This commit is contained in:
parent
ef5e2eb794
commit
a7164f2674
Notes:
sideshowbarker
2024-07-18 08:59:31 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/a7164f2674 Pull-request: https://github.com/SerenityOS/serenity/pull/15359 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/davidot ✅ Reviewed-by: https://github.com/kennethmyhra
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>
|
||||
|
||||
namespace Web::Fetch::Infrastructure {
|
||||
|
@ -20,4 +21,21 @@ Body::Body(JS::Handle<Streams::ReadableStream> stream, SourceType source, Option
|
|||
{
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-body-clone
|
||||
WebIDL::ExceptionOr<Body> Body::clone() const
|
||||
{
|
||||
// To clone a body body, run these steps:
|
||||
|
||||
auto& vm = Bindings::main_thread_vm();
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& window = verify_cast<HTML::Window>(realm.global_object());
|
||||
|
||||
// FIXME: 1. Let « out1, out2 » be the result of teeing body’s stream.
|
||||
// FIXME: 2. Set body’s stream to out1.
|
||||
auto* out2 = vm.heap().allocate<Streams::ReadableStream>(realm, window);
|
||||
|
||||
// 3. Return a body whose stream is out2 and other members are copied from body.
|
||||
return Body { JS::make_handle(out2), m_source, m_length };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ public:
|
|||
[[nodiscard]] SourceType const& source() const { return m_source; }
|
||||
[[nodiscard]] Optional<u64> const& length() const { return m_length; }
|
||||
|
||||
[[nodiscard]] WebIDL::ExceptionOr<Body> clone() const;
|
||||
|
||||
private:
|
||||
// https://fetch.spec.whatwg.org/#concept-body-stream
|
||||
// A stream (a ReadableStream object).
|
||||
|
|
|
@ -158,17 +158,19 @@ ErrorOr<ByteBuffer> Request::byte_serialize_origin() const
|
|||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-request-clone
|
||||
NonnullOwnPtr<Request> Request::clone() const
|
||||
WebIDL::ExceptionOr<NonnullOwnPtr<Request>> Request::clone() const
|
||||
{
|
||||
// To clone a request request, run these steps:
|
||||
|
||||
// 1. Let newRequest be a copy of request, except for its body.
|
||||
BodyType body;
|
||||
swap(body, const_cast<BodyType&>(m_body));
|
||||
auto new_request = adopt_own(*new Infrastructure::Request(*this));
|
||||
swap(body, const_cast<BodyType&>(m_body));
|
||||
BodyType tmp_body;
|
||||
swap(tmp_body, const_cast<BodyType&>(m_body));
|
||||
auto new_request = make<Infrastructure::Request>(*this);
|
||||
swap(tmp_body, const_cast<BodyType&>(m_body));
|
||||
|
||||
// FIXME: 2. If request’s body is non-null, set newRequest’s body to the result of cloning request’s body.
|
||||
// 2. If request’s body is non-null, set newRequest’s body to the result of cloning request’s body.
|
||||
if (auto const* body = m_body.get_pointer<Body>())
|
||||
new_request->set_body(TRY(body->clone()));
|
||||
|
||||
// 3. Return newRequest.
|
||||
return new_request;
|
||||
|
|
|
@ -287,7 +287,7 @@ public:
|
|||
[[nodiscard]] String serialize_origin() const;
|
||||
[[nodiscard]] ErrorOr<ByteBuffer> byte_serialize_origin() const;
|
||||
|
||||
[[nodiscard]] NonnullOwnPtr<Request> clone() const;
|
||||
[[nodiscard]] WebIDL::ExceptionOr<NonnullOwnPtr<Request>> clone() const;
|
||||
|
||||
[[nodiscard]] ErrorOr<void> add_range_reader(u64 first, Optional<u64> const& last);
|
||||
|
||||
|
|
|
@ -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));
|
||||
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));
|
||||
|
||||
// FIXME: 3. If response’s body is non-null, then set newResponse’s body to the result of cloning response’s 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;
|
||||
|
|
|
@ -100,7 +100,7 @@ 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;
|
||||
[[nodiscard]] WebIDL::ExceptionOr<NonnullOwnPtr<Response>> clone() const;
|
||||
|
||||
private:
|
||||
// https://fetch.spec.whatwg.org/#concept-response-type
|
||||
|
|
Loading…
Reference in a new issue