#include <userver/http/header_map.hpp>
Container that maps case-insensitive header name into header value.
Allows storing up to 24576 name->value pairs, after that an attempt to insert a new pair will throw.
Has an anti-hashdos collisions resolution built-in, and the capacity limit might be lowered in case of an attack being detected.
Iterators/pointers invalidation loosely matches that of std::vector:
begin
(it's implemented via swap and pop_back idiom, and begin
is actually an rbegin
of underlying vector). Definition at line 38 of file header_map.hpp.
Classes | |
class | ConstIterator |
class | Iterator |
class | TooManyHeadersException |
The exception being thrown in case of capacity overflow. More... | |
Public Types | |
using | iterator = Iterator |
using | const_iterator = ConstIterator |
using | key_type = std::string |
using | mapped_type = std::string |
Public Member Functions | |
HeaderMap () | |
Default constructor. | |
HeaderMap (std::initializer_list< std::pair< std::string, std::string > > headers) | |
HeaderMap (std::initializer_list< std::pair< PredefinedHeader, std::string > > headers) | |
HeaderMap (std::size_t capacity) | |
template<typename InputIt > | |
HeaderMap (InputIt first, InputIt last) | |
~HeaderMap () | |
Destructor. | |
HeaderMap (const HeaderMap &other) | |
Copy constructor. | |
HeaderMap (HeaderMap &&other) noexcept | |
Move constructor. | |
HeaderMap & | operator= (const HeaderMap &other) |
Copy assignment operator. | |
HeaderMap & | operator= (HeaderMap &&other) noexcept |
Move assignment operator. | |
void | reserve (std::size_t capacity) |
Non-binding call to reserve capacity elements for internal storage. | |
std::size_t | size () const noexcept |
Returns the amount of name-value-pairs being stored. | |
bool | empty () const noexcept |
Return true if no name-value-pairs are being stored, false otherwise. | |
void | clear () |
std::size_t | count (std::string_view key) const noexcept |
Returns 1 if the key exists, 0 otherwise. | |
std::size_t | count (const PredefinedHeader &key) const noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
template<std::size_t Size> | |
std::size_t | count (const char(&)[Size]) const noexcept |
bool | contains (std::string_view key) const noexcept |
Returns true if the key exists, false otherwise. | |
bool | contains (const PredefinedHeader &key) const noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
template<std::size_t Size> | |
bool | contains (const char(&)[Size]) const noexcept |
std::string & | operator[] (std::string &&key) |
std::string & | operator[] (std::string_view key) |
std::string & | operator[] (const PredefinedHeader &key) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
template<std::size_t Size> | |
std::string & | operator[] (const char(&)[Size]) |
Iterator | find (std::string_view key) noexcept |
ConstIterator | find (std::string_view key) const noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Iterator | find (const PredefinedHeader &key) noexcept |
ConstIterator | find (const PredefinedHeader &key) const noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
template<std::size_t Size> | |
Iterator | find (const char(&)[Size]) noexcept |
template<std::size_t Size> | |
ConstIterator | find (const char(&)[Size]) const noexcept |
template<typename... Args> | |
void | emplace (std::string_view key, Args &&... args) |
template<typename... Args> | |
void | emplace (std::string key, Args &&... args) |
template<typename... Args> | |
void | try_emplace (std::string key, Args &&... args) |
template<typename InputIt > | |
void | insert (InputIt first, InputIt last) |
void | insert (const std::pair< std::string, std::string > &kvp) |
void | insert (std::pair< std::string, std::string > &&kvp) |
void | insert_or_assign (std::string key, std::string value) |
void | insert_or_assign (const PredefinedHeader &key, std::string value) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void | InsertOrAppend (std::string key, std::string value) |
void | InsertOrAppend (const PredefinedHeader &key, std::string value) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Iterator | erase (Iterator it) |
Iterator | erase (ConstIterator it) |
Iterator | erase (std::string_view key) |
Iterator | erase (const PredefinedHeader &key) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
template<std::size_t Size> | |
Iterator | erase (const char(&)[Size]) |
std::string & | at (std::string_view key) |
std::string & | at (const PredefinedHeader &key) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const std::string & | at (std::string_view key) const |
const std::string & | at (const PredefinedHeader &key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
template<std::size_t Size> | |
std::string & | at (const char(&)[Size]) |
template<std::size_t Size> | |
const std::string & | at (const char(&)[Size]) const |
Iterator | begin () noexcept |
Returns an iterator to the first name-value-pair being stored. | |
ConstIterator | begin () const noexcept |
Returns an iterator to the first name-value-pair being stored. | |
ConstIterator | cbegin () const noexcept |
Returns an iterator to the first name-value-pair being stored. | |
Iterator | end () noexcept |
Returns an iterator to the end (valid but not dereferenceable). | |
ConstIterator | end () const noexcept |
Returns an iterator to the end (valid but not dereferenceable). | |
ConstIterator | cend () const noexcept |
Returns an iterator to the end (valid but not dereferenceable). | |
bool | operator== (const HeaderMap &other) const noexcept |
void | OutputInHttpFormat (HeadersString &buffer) const |
Definition at line 46 of file header_map.hpp.
Definition at line 45 of file header_map.hpp.
using http::headers::HeaderMap::key_type = std::string |
Definition at line 48 of file header_map.hpp.
using http::headers::HeaderMap::mapped_type = std::string |
Definition at line 49 of file header_map.hpp.
http::headers::HeaderMap::HeaderMap | ( | std::initializer_list< std::pair< std::string, std::string > > | headers | ) |
Constructor from initializer list: HeaderMap({{"a", "b"}, {"c", "d"}})
. Its unspecified which pair is inserted in case of names not being unique.
http::headers::HeaderMap::HeaderMap | ( | std::initializer_list< std::pair< PredefinedHeader, std::string > > | headers | ) |
Constructor from initializer list: HeaderMap({{"a", "b"}, {"c", "d"}})
. Its unspecified which pair is inserted in case of names not being unique.
http::headers::HeaderMap::HeaderMap | ( | std::size_t | capacity | ) |
Constructor with capacity: preallocates capacity
elements for internal storage.
http::headers::HeaderMap::HeaderMap | ( | InputIt | first, |
InputIt | last ) |
Constructor from iterator pair: HeaderMap{key_value_pairs.begin(), key_value_pairs.end()}
. Its unspecified which pair is inserted in case of names not being unique.
Definition at line 275 of file header_map.hpp.
|
inline |
Definition at line 226 of file header_map.hpp.
|
inline |
Definition at line 230 of file header_map.hpp.
std::string & http::headers::HeaderMap::at | ( | std::string_view | key | ) |
If the key is present in container, returns reference to its header value, otherwise throws std::out_of_range.
const std::string & http::headers::HeaderMap::at | ( | std::string_view | key | ) | const |
If the key is present in container, returns reference to its header value, otherwise throws std::out_of_range.
void http::headers::HeaderMap::clear | ( | ) |
Removes all the key-value-pairs being stored, doesn't shrink underlying storage.
|
inlinenoexcept |
Definition at line 111 of file header_map.hpp.
|
inlinenoexcept |
Definition at line 101 of file header_map.hpp.
|
inline |
If the key is already present in the map, does nothing. Otherwise inserts a pair of key and inplace constructed value.
Definition at line 161 of file header_map.hpp.
|
inline |
If the key is already present in the map, does nothing. Otherwise inserts a pair of key and in-place constructed value.
Definition at line 154 of file header_map.hpp.
HeaderMap::Iterator http::headers::HeaderMap::erase | ( | const | char(&)[Size] | ) |
Definition at line 445 of file header_map.hpp.
Iterator http::headers::HeaderMap::erase | ( | ConstIterator | it | ) |
Erases the pair to which the iterator points, returns iterator following the last removed element. Iterators/pointers to erased value and begin
are invalidated.
Erases the pair to which the iterator points, returns iterator following the last removed element. Iterators/pointers to erased value and begin
are invalidated.
Iterator http::headers::HeaderMap::erase | ( | std::string_view | key | ) |
If the key is present in container, behaves exactly like erase(Iterator). Otherwise does nothing and returns end()
.
|
noexcept |
Definition at line 440 of file header_map.hpp.
|
noexcept |
Definition at line 435 of file header_map.hpp.
|
noexcept |
If the key is present, returns iterator to its name-value pair, otherwise return end().
|
noexcept |
If the key is present, returns iterator to its name-value pair, otherwise return end().
void http::headers::HeaderMap::insert | ( | const std::pair< std::string, std::string > & | kvp | ) |
If kvp.first is already present in the map, does nothing, otherwise inserts the pair into container.
void http::headers::HeaderMap::insert | ( | InputIt | first, |
InputIt | last ) |
For every iterator it in [first, last) inserts *it. Its unspecified which pair is inserted in case of names not being unique.
Definition at line 280 of file header_map.hpp.
void http::headers::HeaderMap::insert | ( | std::pair< std::string, std::string > && | kvp | ) |
If kvp.first is already present in the map, does nothing, otherwise inserts the pair into container.
void http::headers::HeaderMap::insert_or_assign | ( | std::string | key, |
std::string | value ) |
If key is already present in the map, changes corresponding header value to provided value, otherwise inserts the pair into container.
void http::headers::HeaderMap::InsertOrAppend | ( | std::string | key, |
std::string | value ) |
If key is already present in the map, appends ",{value}" to the corresponding header value, otherwise inserts the pair into container.
|
noexcept |
Returns true if other
contains exactly the same set of name-value-pairs, false otherwise.
|
inline |
Definition at line 129 of file header_map.hpp.
std::string & http::headers::HeaderMap::operator[] | ( | std::string && | key | ) |
If the key is present, returns reference to it's header value, otherwise inserts a pair (key, "") and returns reference to newly inserted empty string. In an insertion took place, key is moved-out, otherwise key is left unchanged.
std::string & http::headers::HeaderMap::operator[] | ( | std::string_view | key | ) |
If the key is present, returns reference to it's header value, otherwise inserts a pair (key, "") and returns reference to newly inserted empty string.
void http::headers::HeaderMap::OutputInHttpFormat | ( | HeadersString & | buffer | ) | const |
Appends container content in http headers format to provided buffer, that is appends
resizing buffer as needed.
|
inline |
If the key is already present in the map, does nothing. Otherwise inserts a pair of key and inplace constructed value.
Definition at line 168 of file header_map.hpp.
|
friend |
Definition at line 263 of file header_map.hpp.