/* * Copyright (c) 2022-2023, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include namespace Web::Fetch { using HeadersInit = Variant>, OrderedHashMap>; // https://fetch.spec.whatwg.org/#headers-class class Headers final : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(Headers, Bindings::PlatformObject); public: enum class Guard { Immutable, Request, RequestNoCORS, Response, None, }; static WebIDL::ExceptionOr> construct_impl(JS::Realm& realm, Optional const& init); virtual ~Headers() override; [[nodiscard]] JS::NonnullGCPtr header_list() const { return m_header_list; } void set_header_list(JS::NonnullGCPtr header_list) { m_header_list = header_list; } [[nodiscard]] Guard guard() const { return m_guard; } void set_guard(Guard guard) { m_guard = guard; } WebIDL::ExceptionOr fill(HeadersInit const&); WebIDL::ExceptionOr append(Infrastructure::Header); // JS API functions WebIDL::ExceptionOr append(String const& name, String const& value); WebIDL::ExceptionOr delete_(String const& name); WebIDL::ExceptionOr> get(String const& name); WebIDL::ExceptionOr> get_set_cookie(); WebIDL::ExceptionOr has(String const& name); WebIDL::ExceptionOr set(String const& name, String const& value); using ForEachCallback = Function(String const&, String const&)>; JS::ThrowCompletionOr for_each(ForEachCallback); private: friend class HeadersIterator; Headers(JS::Realm&, JS::NonnullGCPtr); virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; virtual void visit_edges(JS::Cell::Visitor&) override; WebIDL::ExceptionOr validate(Infrastructure::Header const&) const; void remove_privileged_no_cors_request_headers(); // https://fetch.spec.whatwg.org/#concept-headers-header-list // A Headers object has an associated header list (a header list), which is initially empty. JS::NonnullGCPtr m_header_list; // https://fetch.spec.whatwg.org/#concept-headers-guard // A Headers object also has an associated guard, which is a headers guard. A headers guard is "immutable", "request", "request-no-cors", "response" or "none". Guard m_guard { Guard::None }; }; }