1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:37:35 +00:00

LibWeb/Fetch: Implement Body's "fully read" function from the spec

Required by XHR's reliance on Fetch.
This commit is contained in:
Luke Wilde 2023-02-28 18:12:44 +00:00 committed by Linus Groh
parent 9aca54091a
commit ccdb1bcc4e
9 changed files with 121 additions and 42 deletions

View file

@ -13,6 +13,7 @@
#include <AK/Variant.h>
#include <LibJS/Heap/GCPtr.h>
#include <LibJS/Heap/Handle.h>
#include <LibWeb/Fetch/Infrastructure/Task.h>
#include <LibWeb/FileAPI/Blob.h>
#include <LibWeb/Streams/ReadableStream.h>
#include <LibWeb/WebIDL/Promise.h>
@ -23,6 +24,8 @@ namespace Web::Fetch::Infrastructure {
class Body final {
public:
using SourceType = Variant<Empty, ByteBuffer, JS::Handle<FileAPI::Blob>>;
using ProcessBodyCallback = JS::SafeFunction<void(ByteBuffer)>;
using ProcessBodyErrorCallback = JS::SafeFunction<void(JS::Object&)>;
explicit Body(JS::Handle<Streams::ReadableStream>);
Body(JS::Handle<Streams::ReadableStream>, SourceType, Optional<u64>);
@ -33,7 +36,7 @@ public:
WebIDL::ExceptionOr<Body> clone(JS::Realm&) const;
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> fully_read_as_promise() const;
WebIDL::ExceptionOr<void> fully_read(JS::Realm&, ProcessBodyCallback process_body, ProcessBodyErrorCallback process_body_error, TaskDestination task_destination) const;
private:
// https://fetch.spec.whatwg.org/#concept-body-stream