1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-16 14:37:35 +00:00
serenity/Userland/Libraries/LibWeb/Fetch/Headers.h
Linus Groh ad04d7ac9b LibWeb: Move ExceptionOr from DOM/ to WebIDL/
This is a concept fully defined in the Web IDL spec and doesn't belong
in the DOM directory/namespace - not even DOMException, despite the name
:^)
2022-09-25 19:13:31 +01:00

65 lines
2.1 KiB
C++

/*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/HashMap.h>
#include <AK/String.h>
#include <AK/Variant.h>
#include <AK/Vector.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Headers.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::Fetch {
using HeadersInit = Variant<Vector<Vector<String>>, OrderedHashMap<String, String>>;
// 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<JS::NonnullGCPtr<Headers>> create_with_global_object(HTML::Window& window, Optional<HeadersInit> const& init);
virtual ~Headers() override;
WebIDL::ExceptionOr<void> append(Infrastructure::Header);
WebIDL::ExceptionOr<void> append(String const& name, String const& value);
WebIDL::ExceptionOr<void> delete_(String const& name);
WebIDL::ExceptionOr<String> get(String const& name);
WebIDL::ExceptionOr<bool> has(String const& name);
WebIDL::ExceptionOr<void> set(String const& name, String const& value);
using ForEachCallback = Function<JS::ThrowCompletionOr<void>(String const&, String const&)>;
JS::ThrowCompletionOr<void> for_each(ForEachCallback);
private:
friend class HeadersIterator;
explicit Headers(HTML::Window&);
WebIDL::ExceptionOr<void> 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 };
};
}