/* * Copyright (c) 2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include namespace Web::Fetch { using HeadersInit = Variant>, OrderedHashMap>; // https://fetch.spec.whatwg.org/#headers-class class Headers : public Bindings::Wrappable , public RefCounted { public: using WrapperType = Bindings::HeadersWrapper; enum class Guard { Immutable, Request, RequestNoCORS, Response, None, }; static DOM::ExceptionOr> create(Optional const&); static DOM::ExceptionOr> create_with_global_object(Bindings::WindowObject&, Optional const& init) { return create(init); } DOM::ExceptionOr append(Infrastructure::Header); DOM::ExceptionOr append(String const& name, String const& value); DOM::ExceptionOr delete_(String const& name); DOM::ExceptionOr get(String const& name); DOM::ExceptionOr has(String const& name); DOM::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() = default; DOM::ExceptionOr fill(HeadersInit const&); void remove_privileged_no_cors_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. Infrastructure::HeaderList 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 }; }; } namespace Web::Bindings { HeadersWrapper* wrap(JS::GlobalObject&, Fetch::Headers&); }