![]() |
Thoth
A functional, expressive, asynchronous C++26 webdev library
|
This class stores the headers from HTTP. More...
#include <Headers.hpp>
Public Types | |
| using | HeaderKey = NHeaders::HeaderKey |
| using | HeaderKeyRef = NHeaders::HeaderKeyRef |
| using | HeaderValue = NHeaders::HeaderValue |
| using | HeaderValueRef = NHeaders::HeaderValueRef |
| using | HeaderPair = NHeaders::HeaderPair |
| using | HeaderPairRef = NHeaders::HeaderPairRef |
| using | MapType = NHeaders::MapType |
| using | MapType = std::vector< HeaderPair > |
| using | IterType = decltype(MapType{}.begin()) |
| using | CIterType = decltype(MapType{}.cbegin()) |
| using | RIterType = decltype(MapType{}.rbegin()) |
| using | CRIterType = decltype(MapType{}.crbegin()) |
Public Member Functions | |
| Headers () | |
| Headers (const MapType &initAs) | |
| Create with an existing vector. | |
| Headers (std::initializer_list< HeaderPair > init) | |
| bool | Exists (HeaderKeyRef key) const |
| check if a key exists. | |
| bool | Exists (HeaderPairRef p) const |
| check if a key exists. | |
| bool | Exists (HeaderKeyRef key, HeaderValueRef val) const |
| check if a key=val exists. | |
| void | Add (HeaderPairRef p) |
| Add a value with the specified key. Append if already exists. | |
| void | Add (HeaderKeyRef key, HeaderValueRef val) |
| same as Add(HeaderPairRef p). | |
| void | Set (HeaderPairRef p) |
| Add a value with the specified key. Replace if already exists. | |
| void | Set (HeaderKeyRef key, HeaderValueRef val) |
| same as Add(HeaderPairRef p). | |
| bool | Remove (HeaderPairRef p) |
| Remove a value with the specified key. | |
| bool | Remove (HeaderKeyRef key, HeaderValueRef val) |
| same as Remove(HeaderPairRef p). | |
| bool | SetIfNull (HeaderPairRef p) |
| If key not exists, set it to value. | |
| bool | SetIfNull (HeaderKeyRef key, HeaderValueRef val) |
| same as SetIfNull(HeaderPairRef p). | |
| std::optional< HeaderValue * > | Get (HeaderKeyRef key) |
| Get the reference of a key but don't create if it not exists. | |
| std::optional< const HeaderValue * > | Get (HeaderKeyRef key) const |
| Get the reference of a key but don't create if it not exists. | |
| IterType | begin () |
| IterType | end () |
| CIterType | begin () const |
| CIterType | end () const |
| RIterType | rbegin () |
| RIterType | rend () |
| CRIterType | rbegin () const |
| CRIterType | rend () const |
| void | Clear () |
| Clear all keys. | |
| size_t | Size () const |
| bool | Empty () const |
| HeaderValue & | operator[] (HeaderKeyRef key) |
| bool | operator== (const Headers &other) const |
Proxies | |
Convenient calls to some headers. | |
| NHeaders::ListProxy< false, NHeaders::MimeType > | Accept () |
| Accept-Encoding header (gzip, br, etc). | |
| NHeaders::ListProxy< true, NHeaders::MimeType > | Accept () const |
| NHeaders::ListProxy< false, NHeaders::AcceptEncodingEnum > | AcceptEncoding () |
| Accept-Encoding header (gzip, br, etc). | |
| NHeaders::ListProxy< true, NHeaders::AcceptEncodingEnum > | AcceptEncoding () const |
| NHeaders::ValueProxy< false, NHeaders::MimeType > | ContentType () |
| Defines the media type of the resource (MIME). | |
| NHeaders::ValueProxy< true, NHeaders::MimeType > | ContentType () const |
| Defines the media type of the resource (MIME). | |
| NHeaders::ValueProxy< false, uint64_t > | ContentLength () |
| The size of the entity-body in bytes. | |
| NHeaders::ValueProxy< true, uint64_t > | ContentLength () const |
| The size of the entity-body in bytes. | |
| NHeaders::ListProxy< false, NHeaders::ContentEncodingEnum > | ContentEncoding () |
| List of encodings (compression) applied to the entity. | |
| NHeaders::ListProxy< true, NHeaders::ContentEncodingEnum > | ContentEncoding () const |
| List of encodings (compression) applied to the entity. | |
| NHeaders::ListProxy< false, NHeaders::TransferEncodingEnum > | TransferEncoding () |
| List of compression applied to the entity. | |
| NHeaders::ListProxy< true, NHeaders::TransferEncodingEnum > | TransferEncoding () const |
| List of compression applied to the entity. | |
| NHeaders::ListProxy< false, std::string > | ContentLanguage () |
| Natural languages for the intended audience (e.g., "en-US"). | |
| NHeaders::ListProxy< true, std::string > | ContentLanguage () const |
| Natural languages for the intended audience (e.g., "en-US"). | |
| NHeaders::ValueProxy< false, std::string > | ContentLocation () |
| The specific location for the entity-body. | |
| NHeaders::ValueProxy< true, std::string > | ContentLocation () const |
| The specific location for the entity-body. | |
| NHeaders::ValueProxy< false, std::chrono::utc_clock::time_point > | Date () |
| Date and time at which the message was originated. | |
| NHeaders::ValueProxy< true, std::chrono::utc_clock::time_point > | Date () const |
| Date and time at which the message was originated. | |
| NHeaders::ListProxy< false, std::string > | Connection () |
| Options for the current connection. | |
| NHeaders::ListProxy< true, std::string > | Connection () const |
| Options for the current connection. | |
| NHeaders::ListProxy< false, NHeaders::Upgrade > | Upgrade () |
| Used to signal a protocol change (e.g., "websocket"). | |
| NHeaders::ListProxy< true, NHeaders::Upgrade > | Upgrade () const |
| Used to signal a protocol change (e.g., "websocket"). | |
| NHeaders::ListProxy< false, std::string > | Trailer () |
| Indicates header fields present in the trailer of a chunked message. | |
| NHeaders::ListProxy< true, std::string > | Trailer () const |
| Indicates header fields present in the trailer of a chunked message. | |
| NHeaders::ListProxy< false, std::string > | Via () |
| Path taken by the request/response through proxies (free std::string). | |
| NHeaders::ListProxy< true, std::string > | Via () const |
| Path taken by the request/response through proxies (free std::string). | |
Static Public Member Functions | |
| template<std::ranges::input_range R> | |
| static WebResult< Headers > | Parse (R &headers, size_t maxHeadersLength=1<< 16) |
| Tries to parse the headers from the raw TCP std::string. | |
| static Headers | DefaultHeaders () |
Friends | |
| struct | std::formatter< Headers > |
This class stores the headers from HTTP.
| using Thoth::Http::Headers::CIterType = decltype(MapType{}.cbegin()) |
| using Thoth::Http::Headers::CRIterType = decltype(MapType{}.crbegin()) |
| using Thoth::Http::Headers::IterType = decltype(MapType{}.begin()) |
| using Thoth::Http::Headers::MapType = std::vector<HeaderPair> |
| using Thoth::Http::Headers::RIterType = decltype(MapType{}.rbegin()) |
| Thoth::Http::Headers::Headers | ( | ) |
|
explicit |
Create with an existing vector.
| Thoth::Http::Headers::Headers | ( | std::initializer_list< HeaderPair > | init | ) |
| NHeaders::ListProxy< false, NHeaders::MimeType > Thoth::Http::Headers::Accept | ( | ) |
Accept-Encoding header (gzip, br, etc).
| NHeaders::ListProxy< true, NHeaders::MimeType > Thoth::Http::Headers::Accept | ( | ) | const |
| NHeaders::ListProxy< false, NHeaders::AcceptEncodingEnum > Thoth::Http::Headers::AcceptEncoding | ( | ) |
Accept-Encoding header (gzip, br, etc).
| NHeaders::ListProxy< true, NHeaders::AcceptEncodingEnum > Thoth::Http::Headers::AcceptEncoding | ( | ) | const |
| void Thoth::Http::Headers::Add | ( | HeaderKeyRef | key, |
| HeaderValueRef | val | ||
| ) |
same as Add(HeaderPairRef p).
| void Thoth::Http::Headers::Add | ( | HeaderPairRef | p | ) |
Add a value with the specified key. Append if already exists.
| p | A pair with the key and the value to be added. |
| IterType Thoth::Http::Headers::begin | ( | ) |
| CIterType Thoth::Http::Headers::begin | ( | ) | const |
| void Thoth::Http::Headers::Clear | ( | ) |
Clear all keys.
| NHeaders::ListProxy< false, std::string > Thoth::Http::Headers::Connection | ( | ) |
Options for the current connection.
| NHeaders::ListProxy< true, std::string > Thoth::Http::Headers::Connection | ( | ) | const |
Options for the current connection.
| NHeaders::ListProxy< false, NHeaders::ContentEncodingEnum > Thoth::Http::Headers::ContentEncoding | ( | ) |
List of encodings (compression) applied to the entity.
| NHeaders::ListProxy< true, NHeaders::ContentEncodingEnum > Thoth::Http::Headers::ContentEncoding | ( | ) | const |
List of encodings (compression) applied to the entity.
| NHeaders::ListProxy< false, std::string > Thoth::Http::Headers::ContentLanguage | ( | ) |
Natural languages for the intended audience (e.g., "en-US").
| NHeaders::ListProxy< true, std::string > Thoth::Http::Headers::ContentLanguage | ( | ) | const |
Natural languages for the intended audience (e.g., "en-US").
| NHeaders::ValueProxy< false, uint64_t > Thoth::Http::Headers::ContentLength | ( | ) |
The size of the entity-body in bytes.
| NHeaders::ValueProxy< true, uint64_t > Thoth::Http::Headers::ContentLength | ( | ) | const |
The size of the entity-body in bytes.
| NHeaders::ValueProxy< false, std::string > Thoth::Http::Headers::ContentLocation | ( | ) |
The specific location for the entity-body.
| NHeaders::ValueProxy< true, std::string > Thoth::Http::Headers::ContentLocation | ( | ) | const |
The specific location for the entity-body.
| NHeaders::ValueProxy< false, NHeaders::MimeType > Thoth::Http::Headers::ContentType | ( | ) |
Defines the media type of the resource (MIME).
| NHeaders::ValueProxy< true, NHeaders::MimeType > Thoth::Http::Headers::ContentType | ( | ) | const |
Defines the media type of the resource (MIME).
| NHeaders::ValueProxy< false, std::chrono::utc_clock::time_point > Thoth::Http::Headers::Date | ( | ) |
Date and time at which the message was originated.
| NHeaders::ValueProxy< true, std::chrono::utc_clock::time_point > Thoth::Http::Headers::Date | ( | ) | const |
Date and time at which the message was originated.
|
static |
| bool Thoth::Http::Headers::Empty | ( | ) | const |
| IterType Thoth::Http::Headers::end | ( | ) |
| CIterType Thoth::Http::Headers::end | ( | ) | const |
| bool Thoth::Http::Headers::Exists | ( | HeaderKeyRef | key | ) | const |
check if a key exists.
| key | The key to be checked. |
| bool Thoth::Http::Headers::Exists | ( | HeaderKeyRef | key, |
| HeaderValueRef | val | ||
| ) | const |
check if a key=val exists.
| key | The key to be checked. |
| val | The value to be checked. |
| bool Thoth::Http::Headers::Exists | ( | HeaderPairRef | p | ) | const |
check if a key exists.
| p | A pair with the key and value to be checked. |
| std::optional< HeaderValue * > Thoth::Http::Headers::Get | ( | HeaderKeyRef | key | ) |
Get the reference of a key but don't create if it not exists.
| key | The key. |
| std::optional< const HeaderValue * > Thoth::Http::Headers::Get | ( | HeaderKeyRef | key | ) | const |
Get the reference of a key but don't create if it not exists.
| key | The key. |
| bool Thoth::Http::Headers::operator== | ( | const Headers & | other | ) | const |
| HeaderValue & Thoth::Http::Headers::operator[] | ( | HeaderKeyRef | key | ) |
|
static |
Tries to parse the headers from the raw TCP std::string.
| headers | the headers separated by "\r\n". |
| maxHeadersLength | the max length that the headers can achieve. |
| RIterType Thoth::Http::Headers::rbegin | ( | ) |
| CRIterType Thoth::Http::Headers::rbegin | ( | ) | const |
| bool Thoth::Http::Headers::Remove | ( | HeaderKeyRef | key, |
| HeaderValueRef | val | ||
| ) |
same as Remove(HeaderPairRef p).
| bool Thoth::Http::Headers::Remove | ( | HeaderPairRef | p | ) |
Remove a value with the specified key.
| p | A pair with the key and the value to be removed. |
| RIterType Thoth::Http::Headers::rend | ( | ) |
| CRIterType Thoth::Http::Headers::rend | ( | ) | const |
| void Thoth::Http::Headers::Set | ( | HeaderKeyRef | key, |
| HeaderValueRef | val | ||
| ) |
same as Add(HeaderPairRef p).
| void Thoth::Http::Headers::Set | ( | HeaderPairRef | p | ) |
Add a value with the specified key. Replace if already exists.
| p | A pair with the key and the value to be added. |
| bool Thoth::Http::Headers::SetIfNull | ( | HeaderKeyRef | key, |
| HeaderValueRef | val | ||
| ) |
same as SetIfNull(HeaderPairRef p).
| bool Thoth::Http::Headers::SetIfNull | ( | HeaderPairRef | p | ) |
If key not exists, set it to value.
| p | A pair with the key and the value to be added. |
| size_t Thoth::Http::Headers::Size | ( | ) | const |
| NHeaders::ListProxy< false, std::string > Thoth::Http::Headers::Trailer | ( | ) |
Indicates header fields present in the trailer of a chunked message.
| NHeaders::ListProxy< true, std::string > Thoth::Http::Headers::Trailer | ( | ) | const |
Indicates header fields present in the trailer of a chunked message.
| NHeaders::ListProxy< false, NHeaders::TransferEncodingEnum > Thoth::Http::Headers::TransferEncoding | ( | ) |
List of compression applied to the entity.
| NHeaders::ListProxy< true, NHeaders::TransferEncodingEnum > Thoth::Http::Headers::TransferEncoding | ( | ) | const |
List of compression applied to the entity.
| NHeaders::ListProxy< false, NHeaders::Upgrade > Thoth::Http::Headers::Upgrade | ( | ) |
Used to signal a protocol change (e.g., "websocket").
| NHeaders::ListProxy< true, NHeaders::Upgrade > Thoth::Http::Headers::Upgrade | ( | ) | const |
Used to signal a protocol change (e.g., "websocket").
| NHeaders::ListProxy< false, std::string > Thoth::Http::Headers::Via | ( | ) |
Path taken by the request/response through proxies (free std::string).
| NHeaders::ListProxy< true, std::string > Thoth::Http::Headers::Via | ( | ) | const |
Path taken by the request/response through proxies (free std::string).
|
friend |