2022-09-25 21:30:24 +03:00
|
|
|
/*
|
2023-03-03 12:27:51 +03:00
|
|
|
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
|
2022-09-25 21:30:24 +03:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Forward.h>
|
|
|
|
#include <LibJS/Forward.h>
|
2023-02-10 16:29:14 +03:00
|
|
|
#include <LibJS/Heap/GCPtr.h>
|
2022-09-25 21:30:24 +03:00
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
|
|
|
|
namespace Web::Fetch {
|
|
|
|
|
|
|
|
enum class PackageDataType {
|
|
|
|
ArrayBuffer,
|
|
|
|
Blob,
|
|
|
|
FormData,
|
|
|
|
JSON,
|
|
|
|
Text,
|
|
|
|
};
|
|
|
|
|
|
|
|
// https://fetch.spec.whatwg.org/#body-mixin
|
|
|
|
class BodyMixin {
|
|
|
|
public:
|
|
|
|
virtual ~BodyMixin();
|
|
|
|
|
2023-03-03 12:27:51 +03:00
|
|
|
virtual ErrorOr<Optional<MimeSniff::MimeType>> mime_type_impl() const = 0;
|
2023-08-18 20:38:13 +03:00
|
|
|
virtual JS::GCPtr<Infrastructure::Body> body_impl() = 0;
|
|
|
|
virtual JS::GCPtr<Infrastructure::Body const> body_impl() const = 0;
|
2023-02-28 21:12:44 +03:00
|
|
|
virtual Bindings::PlatformObject& as_platform_object() = 0;
|
|
|
|
virtual Bindings::PlatformObject const& as_platform_object() const = 0;
|
2022-09-25 21:30:24 +03:00
|
|
|
|
|
|
|
[[nodiscard]] bool is_unusable() const;
|
|
|
|
[[nodiscard]] JS::GCPtr<Streams::ReadableStream> body() const;
|
|
|
|
[[nodiscard]] bool body_used() const;
|
|
|
|
|
|
|
|
// JS API functions
|
2023-02-28 21:12:44 +03:00
|
|
|
[[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> array_buffer() const;
|
|
|
|
[[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> blob() const;
|
|
|
|
[[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> form_data() const;
|
|
|
|
[[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> json() const;
|
|
|
|
[[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> text() const;
|
2022-09-25 21:30:24 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
[[nodiscard]] WebIDL::ExceptionOr<JS::Value> package_data(JS::Realm&, ByteBuffer, PackageDataType, Optional<MimeSniff::MimeType> const&);
|
2023-02-28 21:12:44 +03:00
|
|
|
[[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> consume_body(JS::Realm&, BodyMixin const&, PackageDataType);
|
2022-09-25 21:30:24 +03:00
|
|
|
|
|
|
|
}
|