/* * Copyright (c) 2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #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 Optional mime_type_impl() const = 0; virtual Optional body_impl() = 0; virtual Optional body_impl() const = 0; [[nodiscard]] bool is_unusable() const; [[nodiscard]] JS::GCPtr body() const; [[nodiscard]] bool body_used() const; // JS API functions [[nodiscard]] JS::NonnullGCPtr array_buffer() const; [[nodiscard]] JS::NonnullGCPtr blob() const; [[nodiscard]] JS::NonnullGCPtr form_data() const; [[nodiscard]] JS::NonnullGCPtr json() const; [[nodiscard]] JS::NonnullGCPtr text() const; }; [[nodiscard]] WebIDL::ExceptionOr package_data(JS::Realm&, ByteBuffer, PackageDataType, Optional const&); [[nodiscard]] JS::NonnullGCPtr consume_body(JS::Realm&, BodyMixin const&, PackageDataType); }