C++ Actor Framework 1.0.0
|
Encapsulates meta data for HTTP response. More...
#include <response_header.hpp>
Public Types | |
using | super = header |
Public Member Functions | |
response_header ()=default | |
Default constructor. | |
response_header (response_header &&)=default | |
Move constructor. | |
response_header & | operator= (response_header &&)=default |
Move assignment operator. | |
response_header (const response_header &) | |
Copy constructor. | |
response_header & | operator= (const response_header &) |
Copy assignment operator. | |
void | clear () noexcept override |
Clears the header content and fields. | |
std::string_view | version () const noexcept |
Returns the HTTP version of the request. | |
uint16_t | status () const noexcept |
Returns the HTTP status of the request. | |
std::string_view | status_text () const noexcept |
Returns the HTTP status text of the request. | |
std::pair< http::status, std::string_view > | parse (std::string_view raw) |
Parses a raw response header string and returns a pair containing the status and a description for the status. | |
Public Member Functions inherited from caf::net::http::header | |
virtual | ~header () |
Virtual destructor. | |
header ()=default | |
Default constructor. | |
header (header &&)=default | |
Move constructor. | |
header & | operator= (header &&)=default |
Move assignment operator. | |
header (const header &) | |
Copy constructor. | |
header & | operator= (const header &) |
Copy assignment operator. | |
size_t | num_fields () const noexcept |
Returns the number of fields in the request header. | |
std::pair< std::string_view, std::string_view > | field_at (size_t index) const |
Returns the field at the specified index as a key-value pair. | |
bool | has_field (std::string_view key) const noexcept |
Checks if the request header has a field with the specified key. | |
std::string_view | field (std::string_view key) const noexcept |
Returns the value of the field with the specified key, or an empty view if the field is not found. | |
bool | field_equals (ignore_case_t, std::string_view key, std::string_view val) const noexcept |
Checks whether the field key exists and equals val when using case-insensitive compare of the value. | |
bool | field_equals (std::string_view key, std::string_view val) const noexcept |
Checks whether the field key exists and equals val when using case-sensitive compare of the value. | |
template<class T > | |
std::optional< T > | field_as (std::string_view key) const noexcept |
Returns the value of the field with the specified key as the requested type T, or std::nullopt if the field is not found or cannot be converted. | |
template<class F > | |
void | for_each_field (F &&f) const |
Executes the provided callable f for each field in the request header. | |
bool | chunked_transfer_encoding () const noexcept |
Checks whether the client has defined Transfer-Encoding as chunked . | |
std::optional< size_t > | content_length () const noexcept |
Convenience function for field_as<size_t>("Content-Length") . | |
bool | valid () const noexcept |
Checks if the request header is valid (non-empty). | |
expected< std::string_view > | parse_fields (std::string_view data) |
Parses header fields from the provided data and returns the unprocessed input or error on invalid format. | |
Additional Inherited Members | |
Protected Types inherited from caf::net::http::header | |
using | fields_map = std::vector<std::pair<std::string_view, std::string_view>> |
Protected Member Functions inherited from caf::net::http::header | |
fields_map::const_iterator | find_by_key_icase (std::string_view key) const noexcept |
void | reassign_fields (const header &other) |
Reassigns the shallow map from one address to another. | |
Static Protected Member Functions inherited from caf::net::http::header | |
static std::string_view | remap (const char *base, std::string_view src, const char *new_base) noexcept |
Protected Attributes inherited from caf::net::http::header | |
std::vector< char > | raw_ |
Stores the raw HTTP input. | |
Encapsulates meta data for HTTP response.
This class represents a HTTP response header, providing methods for accessing the HTTP version, status and fields.
|
overridevirtualnoexcept |
Clears the header content and fields.
Reimplemented from caf::net::http::header.
std::pair< status, std::string_view > caf::net::http::response_header::parse | ( | std::string_view | raw | ) |
Parses a raw response header string and returns a pair containing the status and a description for the status.
status::bad_request
on error with a human-readable description of the error, status::ok
otherwise.