RESTinio
|
Header fields map. More...
#include <http_headers.hpp>
Public Types | |
enum class | handling_result_t { continue_enumeration , stop_enumeration } |
The result of handling yet another field value. More... | |
using | fields_container_t = std::vector< http_header_field_t > |
using | const_iterator = fields_container_t::const_iterator |
Type of const_iterator for enumeration of fields. |
Public Member Functions | |
http_header_fields_t () | |
http_header_fields_t (const http_header_fields_t &)=default | |
http_header_fields_t (http_header_fields_t &&)=default | |
virtual | ~http_header_fields_t () |
http_header_fields_t & | operator= (const http_header_fields_t &)=default |
http_header_fields_t & | operator= (http_header_fields_t &&)=default |
void | swap_fields (http_header_fields_t &http_header_fields) |
bool | has_field (string_view_t field_name) const noexcept |
Check field by name. | |
bool | has_field (http_field_t field_id) const noexcept |
Check field by field-id. | |
void | set_field (http_header_field_t http_header_field) |
Set header field via http_header_field_t. | |
void | set_field (std::string field_name, std::string field_value) |
Set field with string pair. | |
void | set_field (http_field_t field_id, std::string field_value) |
Set field with id-value pair. | |
void | add_field (http_field_t field_id, std::string field_value) |
Add a field in the form of id-value pair. | |
void | add_field (std::string field_name, std::string field_value) |
Add a field in the form of name-value pair. | |
void | add_field (http_header_field_t http_header_field) |
Add a field in the form of http_header_field object. | |
void | append_field (string_view_t field_name, string_view_t field_value) |
Append field with name. | |
void | append_field (http_field_t field_id, string_view_t field_value) |
Append field with id. | |
const std::string & | get_field (string_view_t field_name) const |
Get field by name. | |
nullable_pointer_t< const std::string > | try_get_field (string_view_t field_name) const noexcept |
Try to get the value of a field by field name. | |
const std::string & | get_field (http_field_t field_id) const |
Get field by id. | |
nullable_pointer_t< const std::string > | try_get_field (http_field_t field_id) const noexcept |
Try to get the value of a field by field ID. | |
std::string | get_field_or (string_view_t field_name, string_view_t default_value) const |
Get field value by field name or default value if the field not found. | |
std::string | get_field_or (string_view_t field_name, std::string &&default_value) const |
Get field value by field name or default value if the field not found. | |
auto | get_field_or (string_view_t field_name, const char *default_value) const |
Get field by name or default value if the field not found. | |
auto | get_field_or (string_view_t field_name, const std::string &default_value) const |
Get field by name or default value if the field not found. | |
std::string | get_field_or (http_field_t field_id, string_view_t default_value) const |
Get field by id or default value if the field not found. | |
auto | get_field_or (http_field_t field_id, const char *default_value) const |
Get field by id or default value if the field not found. | |
auto | get_field_or (http_field_t field_id, const std::string &default_value) const |
Get field by id or default value if the field not found. | |
std::string | get_field_or (http_field_t field_id, std::string &&default_value) const |
Get field by id or default value if the field not found. | |
bool | remove_field (string_view_t field_name) noexcept |
Remove field by name. | |
bool | remove_field (http_field_t field_id) noexcept |
Remove field by id. | |
std::size_t | remove_all_of (string_view_t field_name) noexcept |
Remove all occurences of a field with specified name. | |
std::size_t | remove_all_of (http_field_t field_id) noexcept |
Remove all occurences of a field with specified id. | |
template<typename Lambda> | |
void | for_each_field (Lambda &&lambda) const noexcept(noexcept(lambda(std::declval< const http_header_field_t & >()))) |
Enumeration of fields. | |
template<typename Lambda> | |
void | for_each_value_of (http_field_t field_id, Lambda &&lambda) const noexcept(noexcept(lambda(std::declval< const string_view_t & >()))) |
Enumeration of each value of a field. | |
template<typename Lambda> | |
void | for_each_value_of (string_view_t field_name, Lambda &&lambda) const noexcept(noexcept(lambda(std::declval< const string_view_t & >()))) |
Enumeration of each value of a field. | |
const_iterator | begin () const noexcept |
const_iterator | end () const noexcept |
auto | fields_count () const noexcept |
Getters of field value which return string_view. | |
string_view_t | value_of (string_view_t name) const |
Get the value of a field or throw if the field not found. | |
string_view_t | value_of (http_field_t field_id) const |
Get the value of a field or throw if the field not found. | |
std::optional< string_view_t > | opt_value_of (string_view_t name) const noexcept |
Get optional value of a field. | |
std::optional< string_view_t > | opt_value_of (http_field_t field_id) const noexcept |
Get optional value of a field. |
Static Public Member Functions | |
static constexpr handling_result_t | continue_enumeration () noexcept |
static constexpr handling_result_t | stop_enumeration () noexcept |
Private Member Functions | |
void | append_last_field (string_view_t field_value) |
Appends last added field. | |
fields_container_t::iterator | find (string_view_t field_name) noexcept |
fields_container_t::const_iterator | cfind (string_view_t field_name) const noexcept |
fields_container_t::iterator | find (http_field_t field_id) noexcept |
fields_container_t::const_iterator | cfind (http_field_t field_id) const noexcept |
Private Attributes | |
fields_container_t | m_fields |
Friends | |
void | impl::append_last_field_accessor (http_header_fields_t &, string_view_t) |
Header fields map.
This class holds a collection of header fields.
There are 2 special cases for fields: Connection and Content-Length This cases are handled separetely from the rest of the fields. And as the implementation of http_header_fields_t doesn't have checks on each field manipulation checking whether field name is Connection or Content-Length it is important to use proper member functions in derived classes for manipulating them.
Since v.0.4.9 there are two groups of methods for accessing values of fields. The first group returns std::string (or references/pointers to std::string). This group includes the following methods: get_field(), get_field_or(), try_get_field().
The second group returns string_view_t or std::optional<string_view_t>. This group includes the following methods: value_of() and opt_value_of().
The first group was created in early versions of RESTinio and is present here for historical and compatibility reasons. They are not deprecated yet but they could be deprecated in newer versions of RESTinio. Because of that the usage of value_of() and opt_value_of() is more preferable.
Definition at line 703 of file http_headers.hpp.
using restinio::http_header_fields_t::const_iterator = fields_container_t::const_iterator |
Type of const_iterator for enumeration of fields.
Definition at line 712 of file http_headers.hpp.
using restinio::http_header_fields_t::fields_container_t = std::vector< http_header_field_t > |
Definition at line 709 of file http_headers.hpp.
|
strong |
The result of handling yet another field value.
A value of that enumeration should be returned by a lambda-function passed to for_each_value_of() method.
Enumerator | |
---|---|
continue_enumeration | Next value of field should be found and passed to the next invocation of handler. |
stop_enumeration | The loop on field values should be stopped. |
Definition at line 721 of file http_headers.hpp.
|
inline |
Definition at line 736 of file http_headers.hpp.
|
default |
|
default |
|
inlinevirtual |
Definition at line 742 of file http_headers.hpp.
|
inline |
Add a field in the form of id-value pair.
If field_id=http_field_t::field_unspecified then function does nothing.
Definition at line 861 of file http_headers.hpp.
|
inline |
Add a field in the form of http_header_field object.
Definition at line 902 of file http_headers.hpp.
|
inline |
Add a field in the form of name-value pair.
Definition at line 883 of file http_headers.hpp.
|
inline |
Append field with id.
If field_id=http_field_t::field_unspecified then function does nothing.
Definition at line 931 of file http_headers.hpp.
|
inline |
Append field with name.
Definition at line 909 of file http_headers.hpp.
|
inlineprivate |
Appends last added field.
This is function is used by http-parser when field value is created by 2 separate invocation of on-header-field-value callback
Function doesn't check if at least one field exists, so it is not in the public interface.
Definition at line 1511 of file http_headers.hpp.
|
inlinenoexcept |
Definition at line 1484 of file http_headers.hpp.
|
inlineprivatenoexcept |
Definition at line 1550 of file http_headers.hpp.
|
inlineprivatenoexcept |
Definition at line 1528 of file http_headers.hpp.
|
inlinestaticconstexprnoexcept |
Definition at line 730 of file http_headers.hpp.
|
inlinenoexcept |
Definition at line 1490 of file http_headers.hpp.
|
inlinenoexcept |
Definition at line 1495 of file http_headers.hpp.
|
inlineprivatenoexcept |
Definition at line 1539 of file http_headers.hpp.
|
inlineprivatenoexcept |
Definition at line 1517 of file http_headers.hpp.
|
inlinenoexcept |
Enumeration of fields.
Calls lambda for each field in the container.
Lambda should have one of the following formats:
This method is noexcept if lambda is noexcept.
Usage example:
Definition at line 1363 of file http_headers.hpp.
|
inlinenoexcept |
Enumeration of each value of a field.
Calls lambda for each value of a field field_id.
Lambda should has one of the following formats:
Usage example:
Definition at line 1403 of file http_headers.hpp.
|
inlinenoexcept |
Enumeration of each value of a field.
Calls lambda for each value of a field field_name.
Lambda should has one of the following formats:
Usage example:
Definition at line 1459 of file http_headers.hpp.
|
inline |
Get field by id.
Definition at line 989 of file http_headers.hpp.
|
inline |
Get field by name.
Definition at line 952 of file http_headers.hpp.
|
inline |
Get field by id or default value if the field not found.
This is just overload for get_field_or(http_field_t,string_view_t);
Definition at line 1124 of file http_headers.hpp.
|
inline |
Get field by id or default value if the field not found.
This is just overload for get_field_or(http_field_t,string_view_t);
Definition at line 1136 of file http_headers.hpp.
|
inline |
Get field by id or default value if the field not found.
Definition at line 1150 of file http_headers.hpp.
|
inline |
Get field by id or default value if the field not found.
Definition at line 1104 of file http_headers.hpp.
|
inline |
Get field by name or default value if the field not found.
This is just overload for get_field_or(string_view_t,string_view_t);
Definition at line 1078 of file http_headers.hpp.
|
inline |
Get field by name or default value if the field not found.
This is just overload for get_field_or(string_view_t,string_view_t);
Definition at line 1090 of file http_headers.hpp.
|
inline |
Get field value by field name or default value if the field not found.
Definition at line 1061 of file http_headers.hpp.
|
inline |
Get field value by field name or default value if the field not found.
Definition at line 1042 of file http_headers.hpp.
|
inlinenoexcept |
Check field by field-id.
Definition at line 767 of file http_headers.hpp.
|
inlinenoexcept |
Check field by name.
Definition at line 755 of file http_headers.hpp.
|
default |
|
default |
|
inlinenoexcept |
Get optional value of a field.
Doesn't throw exception if the field is not found. Empty optional will be returned instead.
Usage example:
field_id | ID of a field. |
Definition at line 1327 of file http_headers.hpp.
|
inlinenoexcept |
Get optional value of a field.
Doesn't throw exception if the field is not found. Empty optional will be returned instead.
Usage example:
name | Name of a field. |
Definition at line 1302 of file http_headers.hpp.
|
inlinenoexcept |
Remove all occurences of a field with specified id.
Definition at line 1247 of file http_headers.hpp.
|
inlinenoexcept |
Remove all occurences of a field with specified name.
Definition at line 1223 of file http_headers.hpp.
|
inlinenoexcept |
Remove field by id.
If there are several occurences of field_id only the first one will be removed.
Definition at line 1200 of file http_headers.hpp.
|
inlinenoexcept |
Remove field by name.
If there are several occurences of field_name only the first one will be removed.
Definition at line 1176 of file http_headers.hpp.
|
inline |
Set field with id-value pair.
If field_id=http_field_t::field_unspecified then function does nothing.
Definition at line 827 of file http_headers.hpp.
|
inline |
Set header field via http_header_field_t.
Definition at line 774 of file http_headers.hpp.
|
inline |
Set field with string pair.
Definition at line 802 of file http_headers.hpp.
|
inlinestaticconstexprnoexcept |
Definition at line 733 of file http_headers.hpp.
|
inline |
Definition at line 748 of file http_headers.hpp.
|
inlinenoexcept |
Try to get the value of a field by field ID.
Usage example:
Definition at line 1023 of file http_headers.hpp.
|
inlinenoexcept |
Try to get the value of a field by field name.
Usage example:
Definition at line 978 of file http_headers.hpp.
|
inline |
Get the value of a field or throw if the field not found.
field_id | ID of a field. |
Definition at line 1282 of file http_headers.hpp.
|
inline |
Get the value of a field or throw if the field not found.
name | Name of a field. |
Definition at line 1273 of file http_headers.hpp.
|
friend |
|
private |
Definition at line 1560 of file http_headers.hpp.