43class HeaderMap
final {
50 using iterator = Iterator;
51 using const_iterator = ConstIterator;
53 using key_type = std::string;
54 using mapped_type = std::string;
57 class TooManyHeadersException
final :
public std::runtime_error {
59 using std::runtime_error::runtime_error;
61 TooManyHeadersException(
const TooManyHeadersException&) =
default;
62 TooManyHeadersException(TooManyHeadersException&&) =
default;
63 TooManyHeadersException& operator=(
const TooManyHeadersException&) =
default;
64 TooManyHeadersException& operator=(TooManyHeadersException&&) =
default;
66 ~TooManyHeadersException()
override;
73 HeaderMap(std::initializer_list<std::pair<std::string_view, std::string_view>> headers);
80 template <
typename InputIt>
93 HeaderMap&
operator=(HeaderMap&& other)
noexcept;
98 std::size_t
size()
const noexcept;
106 std::size_t
count(std::string_view key)
const noexcept;
108 std::size_t
count(
const PredefinedHeader& key)
const noexcept;
110 template <std::size_t Size>
111 [[noreturn]] std::size_t count(
const char (&)[Size])
const noexcept {
112 ReportMisuse<Size>();
116 bool contains(std::string_view key)
const noexcept;
118 bool contains(
const PredefinedHeader& key)
const noexcept;
120 template <std::size_t Size>
121 [[noreturn]]
bool contains(
const char (&)[Size])
const noexcept {
122 ReportMisuse<Size>();
136 std::string&
operator[](
const PredefinedHeader& key);
138 template <std::size_t Size>
139 [[noreturn]] std::string& operator[](
const char (&)[Size]) {
140 ReportMisuse<Size>();
145 Iterator
find(std::string_view key)
noexcept;
147 ConstIterator
find(std::string_view key)
const noexcept;
151 Iterator
find(
const PredefinedHeader& key)
noexcept;
153 ConstIterator
find(
const PredefinedHeader& key)
const noexcept;
155 template <std::size_t Size>
156 [[noreturn]] Iterator find(
const char (&)[Size])
noexcept;
158 template <std::size_t Size>
159 [[noreturn]] ConstIterator find(
const char (&)[Size])
const noexcept;
163 template <
typename... Args>
164 void emplace(std::string_view key, Args&&... args) {
165 Emplace(std::move(key), std::forward<Args>(args)...);
170 template <
typename... Args>
171 void emplace(std::string key, Args&&... args) {
172 Emplace(std::move(key), std::forward<Args>(args)...);
177 template <
typename... Args>
179 Emplace(std::move(key), std::forward<Args>(args)...);
184 template <
typename InputIt>
185 void insert(InputIt first, InputIt last);
189 void insert(
const std::pair<std::string, std::string>& kvp);
192 void insert(std::pair<std::string, std::string>&& kvp);
217 Iterator
erase(std::string_view key);
219 Iterator
erase(
const PredefinedHeader& key);
221 template <std::size_t Size>
222 [[noreturn]] Iterator erase(
const char (&)[Size]);
226 std::string&
at(std::string_view key);
228 std::string&
at(
const PredefinedHeader& key);
231 const std::string&
at(std::string_view key)
const;
233 const std::string&
at(
const PredefinedHeader& key)
const;
235 template <std::size_t Size>
236 [[noreturn]] std::string& at(
const char (&)[Size]) {
237 ReportMisuse<Size>();
239 template <std::size_t Size>
240 [[noreturn]]
const std::string& at(
const char (&)[Size])
const {
241 ReportMisuse<Size>();
247 ConstIterator
begin()
const noexcept;
254 ConstIterator
end()
const noexcept;
256 ConstIterator
cend()
const noexcept;
260 bool operator==(
const HeaderMap& other)
const noexcept;
273 friend class TestsHelper;
275 template <
typename KeyType,
typename... Args>
276 void Emplace(KeyType&& key, Args&&... args);
278 template <std::size_t Size>
279 [[noreturn]]
static void ReportMisuse();
320class MapEntry
final {
325 MapEntry(std::string&& key, std::string&& value);
327 MapEntry(
const MapEntry& other);
328 MapEntry& operator=(
const MapEntry& other);
329 MapEntry(MapEntry&& other)
noexcept;
330 MapEntry& operator=(MapEntry&& other)
noexcept;
332 std::pair<
const std::string, std::string>& Get();
333 const std::pair<
const std::string, std::string>& Get()
const;
335 std::pair<std::string, std::string>& GetMutable();
337 bool operator==(
const MapEntry& other)
const;
351 std::pair<std::string, std::string> mutable_value;
352 std::pair<
const std::string, std::string> value;
360class HeaderMap::Iterator
final {
362 using iterator_category = std::forward_iterator_tag;
363 using difference_type = std::ptrdiff_t;
364 using value_type = std::pair<
const std::string, std::string>;
365 using reference = value_type&;
366 using const_reference =
const value_type&;
367 using pointer = value_type*;
368 using const_pointer =
const value_type*;
373 using UnderlyingIterator = std::vector<
header_map::MapEntry>::reverse_iterator;
376 explicit Iterator(UnderlyingIterator it);
379 Iterator(
const Iterator& other);
380 Iterator(Iterator&& other)
noexcept;
381 Iterator& operator=(
const Iterator& other);
382 Iterator& operator=(Iterator&& other)
noexcept;
384 Iterator operator++(
int);
385 Iterator& operator++();
387 reference operator*()
const;
388 pointer operator->()
const;
390 bool operator==(
const Iterator& other)
const;
391 bool operator!=(
const Iterator& other)
const;
393 bool operator==(
const ConstIterator& other)
const;
396 friend class HeaderMap::ConstIterator;
398 UnderlyingIterator it_{};
401class HeaderMap::ConstIterator
final {
403 using iterator_category = std::forward_iterator_tag;
404 using difference_type = std::ptrdiff_t;
405 using value_type = std::pair<
const std::string, std::string>;
406 using reference =
const value_type&;
407 using const_reference =
const value_type&;
408 using pointer =
const value_type*;
409 using const_pointer =
const value_type*;
414 using UnderlyingIterator = std::vector<
header_map::MapEntry>::const_reverse_iterator;
417 explicit ConstIterator(UnderlyingIterator it);
420 ConstIterator(
const ConstIterator& other);
421 ConstIterator(ConstIterator&& other)
noexcept;
422 ConstIterator& operator=(
const ConstIterator& other);
423 ConstIterator& operator=(ConstIterator&& other)
noexcept;
425 ConstIterator operator++(
int);
426 ConstIterator& operator++();
428 const_reference operator*()
const;
429 const_pointer operator->()
const;
431 bool operator==(
const ConstIterator& other)
const;
432 bool operator!=(
const ConstIterator& other)
const;
434 bool operator==(
const Iterator& other)
const;
437 friend class HeaderMap::Iterator;
439 UnderlyingIterator it_{};