/* * Copyright (c) 2024, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include namespace HTTP { class HeaderMap { public: HeaderMap() = default; ~HeaderMap() = default; HeaderMap(Vector
headers) : m_headers(move(headers)) { for (auto& header : m_headers) m_map.set(header.name, header.value); } HeaderMap(HeaderMap const&) = default; HeaderMap(HeaderMap&&) = default; HeaderMap& operator=(HeaderMap const&) = default; HeaderMap& operator=(HeaderMap&&) = default; void set(ByteString name, ByteString value) { m_map.set(name, value); m_headers.append({ move(name), move(value) }); } [[nodiscard]] bool contains(ByteString const& name) const { return m_map.contains(name); } [[nodiscard]] Optional get(ByteString const& name) const { return m_map.get(name); } [[nodiscard]] Vector
const& headers() const { return m_headers; } private: HashMap m_map; Vector
m_headers; }; } namespace IPC { template<> inline ErrorOr encode(Encoder& encoder, HTTP::HeaderMap const& header_map) { TRY(encoder.encode(header_map.headers())); return {}; } template<> inline ErrorOr decode(Decoder& decoder) { auto headers = TRY(decoder.decode>()); return HTTP::HeaderMap { move(headers) }; } }