/* * Copyright (c) 2022-2023, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Web::Fetch { enum class PackageDataType { ArrayBuffer, Blob, FormData, JSON, Text, }; // https://fetch.spec.whatwg.org/#body-mixin class BodyMixin { public: virtual ~BodyMixin(); virtual ErrorOr> mime_type_impl() const = 0; virtual Optional body_impl() = 0; virtual Optional body_impl() const = 0; virtual Bindings::PlatformObject& as_platform_object() = 0; virtual Bindings::PlatformObject const& as_platform_object() const = 0; [[nodiscard]] bool is_unusable() const; [[nodiscard]] JS::GCPtr body() const; [[nodiscard]] bool body_used() const; // JS API functions [[nodiscard]] WebIDL::ExceptionOr> array_buffer() const; [[nodiscard]] WebIDL::ExceptionOr> blob() const; [[nodiscard]] WebIDL::ExceptionOr> form_data() const; [[nodiscard]] WebIDL::ExceptionOr> json() const; [[nodiscard]] WebIDL::ExceptionOr> text() const; }; [[nodiscard]] WebIDL::ExceptionOr package_data(JS::Realm&, ByteBuffer, PackageDataType, Optional const&); [[nodiscard]] WebIDL::ExceptionOr> consume_body(JS::Realm&, BodyMixin const&, PackageDataType); }