/* * Copyright (c) 2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include namespace Web::Fetch { // https://fetch.spec.whatwg.org/#requestinfo using RequestInfo = Variant, DeprecatedString>; // https://fetch.spec.whatwg.org/#requestinit struct RequestInit { Optional method; Optional headers; Optional> body; Optional referrer; Optional referrer_policy; Optional mode; Optional credentials; Optional cache; Optional redirect; Optional integrity; Optional keepalive; Optional> signal; Optional duplex; Optional window; // https://infra.spec.whatwg.org/#map-is-empty bool is_empty() const { return !(method.has_value() || headers.has_value() || body.has_value() || referrer.has_value() || referrer_policy.has_value() || mode.has_value() || credentials.has_value() || cache.has_value() || redirect.has_value() || integrity.has_value() || keepalive.has_value() || signal.has_value() || duplex.has_value() || window.has_value()); } }; // https://fetch.spec.whatwg.org/#request class Request final : public Bindings::PlatformObject , public BodyMixin { WEB_PLATFORM_OBJECT(Request, Bindings::PlatformObject); public: [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm&, JS::NonnullGCPtr, Headers::Guard); static WebIDL::ExceptionOr> construct_impl(JS::Realm&, RequestInfo const& input, RequestInit const& init = {}); virtual ~Request() override; // ^BodyMixin virtual Optional mime_type_impl() const override; virtual Optional body_impl() override; virtual Optional body_impl() const override; [[nodiscard]] JS::NonnullGCPtr request() const { return m_request; } // JS API functions [[nodiscard]] DeprecatedString method() const; [[nodiscard]] DeprecatedString url() const; [[nodiscard]] JS::NonnullGCPtr headers() const; [[nodiscard]] Bindings::RequestDestination destination() const; [[nodiscard]] DeprecatedString referrer() const; [[nodiscard]] Bindings::ReferrerPolicy referrer_policy() const; [[nodiscard]] Bindings::RequestMode mode() const; [[nodiscard]] Bindings::RequestCredentials credentials() const; [[nodiscard]] Bindings::RequestCache cache() const; [[nodiscard]] Bindings::RequestRedirect redirect() const; [[nodiscard]] DeprecatedString integrity() const; [[nodiscard]] bool keepalive() const; [[nodiscard]] bool is_reload_navigation() const; [[nodiscard]] bool is_history_navigation() const; [[nodiscard]] JS::NonnullGCPtr signal() const; [[nodiscard]] Bindings::RequestDuplex duplex() const; [[nodiscard]] WebIDL::ExceptionOr> clone() const; private: Request(JS::Realm&, JS::NonnullGCPtr); virtual void visit_edges(Cell::Visitor&) override; // https://fetch.spec.whatwg.org/#concept-request-request // A Request object has an associated request (a request). JS::NonnullGCPtr m_request; // https://fetch.spec.whatwg.org/#request-headers // A Request object also has an associated headers (null or a Headers object), initially null. JS::GCPtr m_headers; // https://fetch.spec.whatwg.org/#request-signal // A Request object has an associated signal (null or an AbortSignal object), initially null. JS::GCPtr m_signal; }; }