Thoth
A functional, expressive, asynchronous C++26 webdev library
Loading...
Searching...
No Matches
Thoth::Http::RequestHeaders Struct Reference

Represents the collection of HTTP headers associated with a request. Based on modern HTTP RFCs and inspired by .NET's HttpRequestHeaders. More...

#include <RequestHeaders.hpp>

Inheritance diagram for Thoth::Http::RequestHeaders:
[legend]

Public Member Functions

NHeaders::ListProxy< false, stringAcceptLanguage ()
 The value of the Accept-Language header.
 
NHeaders::ListProxy< true, stringAcceptLanguage () const
 
NHeaders::ListProxy< false, NHeaders::TeEnumTe ()
 The value of the TE (Transfer Encoding) header.
 
NHeaders::ListProxy< true, NHeaders::TeEnumTe () const
 
Raw and Collection Views

Methods for accessing headers without immediate parsing or as raw collections.

auto GetNonValidatedView () const
 Gets a view of the contents of this headers collection that does not parse nor validate data.
 
auto GetCookiesView () const
 Gets a readonly view of all Cookie values.
 
- Public Member Functions inherited from Thoth::Http::Headers
 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
 
HeaderValueoperator[] (HeaderKeyRef key)
 
bool operator== (const Headers &other) const
 
NHeaders::ListProxy< false, NHeaders::MimeTypeAccept ()
 Accept-Encoding header (gzip, br, etc).
 
NHeaders::ListProxy< true, NHeaders::MimeTypeAccept () const
 
NHeaders::ListProxy< false, NHeaders::AcceptEncodingEnumAcceptEncoding ()
 Accept-Encoding header (gzip, br, etc).
 
NHeaders::ListProxy< true, NHeaders::AcceptEncodingEnumAcceptEncoding () const
 
NHeaders::ValueProxy< false, NHeaders::MimeTypeContentType ()
 Defines the media type of the resource (MIME).
 
NHeaders::ValueProxy< true, NHeaders::MimeTypeContentType () 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::ContentEncodingEnumContentEncoding ()
 List of encodings (compression) applied to the entity.
 
NHeaders::ListProxy< true, NHeaders::ContentEncodingEnumContentEncoding () const
 List of encodings (compression) applied to the entity.
 
NHeaders::ListProxy< false, NHeaders::TransferEncodingEnumTransferEncoding ()
 List of compression applied to the entity.
 
NHeaders::ListProxy< true, NHeaders::TransferEncodingEnumTransferEncoding () 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::UpgradeUpgrade ()
 Used to signal a protocol change (e.g., "websocket").
 
NHeaders::ListProxy< true, NHeaders::UpgradeUpgrade () 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).
 

Request Specific Proxies

Convenient calls to some headers.

using Url = string
 
NHeaders::ValueProxy< false, std::string > Authorization ()
 
NHeaders::ValueProxy< true, std::string > Authorization () const
 
NHeaders::ValueProxy< false, UrlHost ()
 Gets the Host header. Essential for HTTP/1.1 and SNI.
 
NHeaders::ValueProxy< true, UrlHost () const
 
NHeaders::ValueProxy< false, UrlReferrer ()
 The value of the Referer header (yes, it's misspelled in RFC).
 
NHeaders::ValueProxy< true, UrlReferrer () const
 
NHeaders::ValueProxy< false, Url, std::monostate > Origin ()
 The value of the Origin header. Used for CORS requests.
 
NHeaders::ValueProxy< true, Url, std::monostate > Origin () const
 
NHeaders::ValueProxy< false, stringFrom ()
 The value of the From header (email address of the user).
 
NHeaders::ValueProxy< true, stringFrom () const
 
NHeaders::ValueProxy< false, unsigned int > MaxForwards ()
 The value of the Max-Forwards header for limiting proxy hops.
 
NHeaders::ValueProxy< true, unsigned int > MaxForwards () const
 
NHeaders::ValueProxy< false, stringProxyAuthorization ()
 The value of the Proxy-Authorization header.
 
NHeaders::ValueProxy< true, stringProxyAuthorization () const
 
NHeaders::ListProxy< false, NHeaders::RangeRange ()
 The value of the Range header for partial content requests.
 
NHeaders::ListProxy< true, NHeaders::RangeRange () const
 
NHeaders::ValueProxy< false, std::chrono::utc_clock::time_point > IfModifiedSince ()
 The value of the If-Modified-Since header.
 
NHeaders::ValueProxy< true, std::chrono::utc_clock::time_point > IfModifiedSince () const
 
NHeaders::ValueProxy< false, std::chrono::utc_clock::time_point > IfUnmodifiedSince ()
 The value of the If-Unmodified-Since header.
 
NHeaders::ValueProxy< true, std::chrono::utc_clock::time_point > IfUnmodifiedSince () const
 
NHeaders::ValueProxy< false, std::chrono::utc_clock::time_point, stringIfRange ()
 The value of the If-Range header.
 
NHeaders::ValueProxy< true, std::chrono::utc_clock::time_point, stringIfRange () const
 
NHeaders::ListProxy< false, NHeaders::EntityTagIfMatch ()
 The value of the If-Match header.
 
NHeaders::ListProxy< true, NHeaders::EntityTagIfMatch () const
 
NHeaders::ValueProxy< false, NHeaders::EntityTagIfNoneMatch ()
 The value of the If-None-Match header.
 
NHeaders::ValueProxy< true, NHeaders::EntityTagIfNoneMatch () const
 

Additional Inherited Members

- Public Types inherited from Thoth::Http::Headers
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())
 
- Static Public Member Functions inherited from Thoth::Http::Headers
template<std::ranges::input_range R>
static WebResult< HeadersParse (R &headers, size_t maxHeadersLength=1<< 16)
 Tries to parse the headers from the raw TCP std::string.
 
static Headers DefaultHeaders ()
 

Detailed Description

Represents the collection of HTTP headers associated with a request. Based on modern HTTP RFCs and inspired by .NET's HttpRequestHeaders.

Member Typedef Documentation

◆ Url

Member Function Documentation

◆ AcceptLanguage() [1/2]

NHeaders::ListProxy< false, string > Thoth::Http::RequestHeaders::AcceptLanguage ( )

The value of the Accept-Language header.

◆ AcceptLanguage() [2/2]

NHeaders::ListProxy< true, string > Thoth::Http::RequestHeaders::AcceptLanguage ( ) const

◆ Authorization() [1/2]

NHeaders::ValueProxy< false, std::string > Thoth::Http::RequestHeaders::Authorization ( )

◆ Authorization() [2/2]

NHeaders::ValueProxy< true, std::string > Thoth::Http::RequestHeaders::Authorization ( ) const

◆ From() [1/2]

NHeaders::ValueProxy< false, string > Thoth::Http::RequestHeaders::From ( )

The value of the From header (email address of the user).

◆ From() [2/2]

NHeaders::ValueProxy< true, string > Thoth::Http::RequestHeaders::From ( ) const

◆ GetCookiesView()

auto Thoth::Http::RequestHeaders::GetCookiesView ( ) const

Gets a readonly view of all Cookie values.

Warning
Risk of dangling reference if the underlying collection is modified.

◆ GetNonValidatedView()

auto Thoth::Http::RequestHeaders::GetNonValidatedView ( ) const

Gets a view of the contents of this headers collection that does not parse nor validate data.

◆ Host() [1/2]

NHeaders::ValueProxy< false, Url > Thoth::Http::RequestHeaders::Host ( )

Gets the Host header. Essential for HTTP/1.1 and SNI.

◆ Host() [2/2]

NHeaders::ValueProxy< true, Url > Thoth::Http::RequestHeaders::Host ( ) const

◆ IfMatch() [1/2]

NHeaders::ListProxy< false, NHeaders::EntityTag > Thoth::Http::RequestHeaders::IfMatch ( )

The value of the If-Match header.

◆ IfMatch() [2/2]

NHeaders::ListProxy< true, NHeaders::EntityTag > Thoth::Http::RequestHeaders::IfMatch ( ) const

◆ IfModifiedSince() [1/2]

NHeaders::ValueProxy< false, std::chrono::utc_clock::time_point > Thoth::Http::RequestHeaders::IfModifiedSince ( )

The value of the If-Modified-Since header.

◆ IfModifiedSince() [2/2]

NHeaders::ValueProxy< true, std::chrono::utc_clock::time_point > Thoth::Http::RequestHeaders::IfModifiedSince ( ) const

◆ IfNoneMatch() [1/2]

NHeaders::ValueProxy< false, NHeaders::EntityTag > Thoth::Http::RequestHeaders::IfNoneMatch ( )

The value of the If-None-Match header.

◆ IfNoneMatch() [2/2]

NHeaders::ValueProxy< true, NHeaders::EntityTag > Thoth::Http::RequestHeaders::IfNoneMatch ( ) const

◆ IfRange() [1/2]

NHeaders::ValueProxy< false, std::chrono::utc_clock::time_point, string > Thoth::Http::RequestHeaders::IfRange ( )

The value of the If-Range header.

◆ IfRange() [2/2]

NHeaders::ValueProxy< true, std::chrono::utc_clock::time_point, string > Thoth::Http::RequestHeaders::IfRange ( ) const

◆ IfUnmodifiedSince() [1/2]

NHeaders::ValueProxy< false, std::chrono::utc_clock::time_point > Thoth::Http::RequestHeaders::IfUnmodifiedSince ( )

The value of the If-Unmodified-Since header.

◆ IfUnmodifiedSince() [2/2]

NHeaders::ValueProxy< true, std::chrono::utc_clock::time_point > Thoth::Http::RequestHeaders::IfUnmodifiedSince ( ) const

◆ MaxForwards() [1/2]

NHeaders::ValueProxy< false, unsigned int > Thoth::Http::RequestHeaders::MaxForwards ( )

The value of the Max-Forwards header for limiting proxy hops.

◆ MaxForwards() [2/2]

NHeaders::ValueProxy< true, unsigned int > Thoth::Http::RequestHeaders::MaxForwards ( ) const

◆ Origin() [1/2]

NHeaders::ValueProxy< false, Url, std::monostate > Thoth::Http::RequestHeaders::Origin ( )

The value of the Origin header. Used for CORS requests.

◆ Origin() [2/2]

NHeaders::ValueProxy< true, Url, std::monostate > Thoth::Http::RequestHeaders::Origin ( ) const

◆ ProxyAuthorization() [1/2]

NHeaders::ValueProxy< false, string > Thoth::Http::RequestHeaders::ProxyAuthorization ( )

The value of the Proxy-Authorization header.

◆ ProxyAuthorization() [2/2]

NHeaders::ValueProxy< true, string > Thoth::Http::RequestHeaders::ProxyAuthorization ( ) const

◆ Range() [1/2]

NHeaders::ListProxy< false, NHeaders::Range > Thoth::Http::RequestHeaders::Range ( )

The value of the Range header for partial content requests.

◆ Range() [2/2]

NHeaders::ListProxy< true, NHeaders::Range > Thoth::Http::RequestHeaders::Range ( ) const

◆ Referrer() [1/2]

NHeaders::ValueProxy< false, Url > Thoth::Http::RequestHeaders::Referrer ( )

The value of the Referer header (yes, it's misspelled in RFC).

◆ Referrer() [2/2]

NHeaders::ValueProxy< true, Url > Thoth::Http::RequestHeaders::Referrer ( ) const

◆ Te() [1/2]

NHeaders::ListProxy< false, NHeaders::TeEnum > Thoth::Http::RequestHeaders::Te ( )

The value of the TE (Transfer Encoding) header.

◆ Te() [2/2]

NHeaders::ListProxy< true, NHeaders::TeEnum > Thoth::Http::RequestHeaders::Te ( ) const

The documentation for this struct was generated from the following file: