mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
The end goal here is for LibHTTP to be the home of our RFC 9111 (HTTP caching) implementation. We currently have one implementation in LibWeb for our in-memory cache and another in RequestServer for our disk cache. The implementations both largely revolve around interacting with HTTP headers. But in LibWeb, we are using Fetch's header infra, and in RS we are using are home-grown header infra from LibHTTP. So to give these a common denominator, this patch replaces the LibHTTP implementation with Fetch's infra. Our existing LibHTTP implementation was not particularly compliant with any spec, so this at least gives us a standards-based common implementation. This migration also required moving a handful of other Fetch AOs over to LibHTTP. (It turns out these AOs were all from the Fetch/Infra/HTTP folder, so perhaps it makes sense for LibHTTP to be the implementation of that entire set of facilities.)
61 lines
1.8 KiB
C++
61 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
|
|
* Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/ByteString.h>
|
|
#include <AK/HashTable.h>
|
|
#include <AK/NonnullRefPtr.h>
|
|
#include <AK/Optional.h>
|
|
#include <AK/RefCounted.h>
|
|
#include <AK/String.h>
|
|
#include <AK/Vector.h>
|
|
#include <LibHTTP/Header.h>
|
|
|
|
namespace HTTP {
|
|
|
|
// https://fetch.spec.whatwg.org/#concept-header-list
|
|
class HeaderList final : public RefCounted<HeaderList> {
|
|
public:
|
|
static NonnullRefPtr<HeaderList> create(Vector<Header> = {});
|
|
|
|
Vector<Header> const& headers() const { return m_headers; }
|
|
|
|
[[nodiscard]] bool is_empty() const { return m_headers.is_empty(); }
|
|
|
|
[[nodiscard]] auto begin() { return m_headers.begin(); }
|
|
[[nodiscard]] auto begin() const { return m_headers.begin(); }
|
|
|
|
[[nodiscard]] auto end() { return m_headers.end(); }
|
|
[[nodiscard]] auto end() const { return m_headers.end(); }
|
|
|
|
void clear() { m_headers.clear(); }
|
|
|
|
[[nodiscard]] bool contains(StringView) const;
|
|
Optional<ByteString> get(StringView) const;
|
|
Optional<Vector<String>> get_decode_and_split(StringView) const;
|
|
void append(Header);
|
|
void delete_(StringView name);
|
|
void set(Header);
|
|
void combine(Header);
|
|
[[nodiscard]] Vector<Header> sort_and_combine() const;
|
|
|
|
struct ExtractHeaderParseFailure { };
|
|
[[nodiscard]] Variant<Empty, Vector<ByteString>, ExtractHeaderParseFailure> extract_header_list_values(StringView) const;
|
|
|
|
struct ExtractLengthFailure { };
|
|
[[nodiscard]] Variant<Empty, u64, ExtractLengthFailure> extract_length() const;
|
|
|
|
[[nodiscard]] Vector<ByteString> unique_names() const;
|
|
|
|
private:
|
|
explicit HeaderList(Vector<Header>);
|
|
|
|
Vector<Header> m_headers;
|
|
};
|
|
|
|
}
|