2024-06-09 11:28:37 +02:00
|
|
|
/*
|
2025-11-26 14:13:23 -05:00
|
|
|
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
|
2024-06-09 11:28:37 +02:00
|
|
|
* Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/ByteString.h>
|
2025-11-26 14:13:23 -05:00
|
|
|
#include <AK/StringView.h>
|
|
|
|
|
#include <LibIPC/Forward.h>
|
2024-06-09 11:28:37 +02:00
|
|
|
|
|
|
|
|
namespace HTTP {
|
|
|
|
|
|
2025-11-26 14:13:23 -05:00
|
|
|
// https://fetch.spec.whatwg.org/#concept-header
|
2024-06-09 11:28:37 +02:00
|
|
|
struct Header {
|
2025-11-26 14:13:23 -05:00
|
|
|
[[nodiscard]] static Header isomorphic_encode(StringView, StringView);
|
|
|
|
|
|
|
|
|
|
Optional<Vector<ByteString>> extract_header_values() const;
|
|
|
|
|
|
2024-06-09 11:28:37 +02:00
|
|
|
ByteString name;
|
|
|
|
|
ByteString value;
|
|
|
|
|
};
|
|
|
|
|
|
2025-11-26 14:13:23 -05:00
|
|
|
[[nodiscard]] bool is_header_name(StringView);
|
|
|
|
|
[[nodiscard]] bool is_header_value(StringView);
|
|
|
|
|
[[nodiscard]] ByteString normalize_header_value(StringView);
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] bool is_forbidden_request_header(Header const&);
|
|
|
|
|
[[nodiscard]] bool is_forbidden_response_header_name(StringView);
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] Vector<String> get_decode_and_split_header_value(StringView value);
|
|
|
|
|
[[nodiscard]] Vector<ByteString> convert_header_names_to_a_sorted_lowercase_set(ReadonlySpan<ByteString> header_names);
|
|
|
|
|
|
|
|
|
|
struct RangeHeaderValue {
|
|
|
|
|
Optional<u64> start;
|
|
|
|
|
Optional<u64> end;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] ByteString build_content_range(u64 range_start, u64 range_end, u64 full_length);
|
|
|
|
|
Optional<RangeHeaderValue> parse_single_range_header_value(StringView, bool allow_whitespace);
|
|
|
|
|
|
2024-06-09 11:28:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
|
|
|
|
|
template<>
|
2025-11-26 14:13:23 -05:00
|
|
|
ErrorOr<void> encode(Encoder& encoder, HTTP::Header const& header);
|
2024-06-09 11:28:37 +02:00
|
|
|
|
|
|
|
|
template<>
|
2025-11-26 14:13:23 -05:00
|
|
|
ErrorOr<HTTP::Header> decode(Decoder& decoder);
|
2024-06-09 11:28:37 +02:00
|
|
|
|
|
|
|
|
}
|