Cutelyst  2.13.0
Public Member Functions | List of all members
Cutelyst::Headers Class Reference

Public Member Functions

 Headers ()=default
 
 Headers (const Headers &other)
 
 Headers (std::initializer_list< std::pair< QString, QString > > list)
 
QString authorization () const
 
QString authorizationBasic () const
 
std::pair< QString, QString > authorizationBasicPair () const
 
void clear ()
 
QString connection () const
 
bool contains (const QString &field)
 
QString contentDisposition () const
 
QString contentEncoding () const
 
bool contentIsHtml () const
 
bool contentIsJson () const
 
bool contentIsText () const
 
bool contentIsXHtml () const
 
bool contentIsXml () const
 
qint64 contentLength () const
 
QString contentType () const
 
QString contentTypeCharset () const
 
QHash< QString, QString > data () const
 
QDateTime date () const
 
QString header (const QString &field) const
 
QString header (const QString &field, const QString &defaultValue) const
 
QString host () const
 
bool ifMatch (const QString &etag) const
 
QString ifModifiedSince () const
 
bool ifModifiedSince (const QDateTime &lastModified) const
 
QDateTime ifModifiedSinceDateTime () const
 
bool ifNoneMatch (const QString &etag) const
 
QString lastModified () const
 
 operator QVariant () const
 
bool operator!= (const Headers &other) const
 
Headersoperator= (const Headers &other)
 
bool operator== (const Headers &other) const
 
QString & operator[] (const QString &key)
 
const QString operator[] (const QString &key) const
 
QString proxyAuthorization () const
 
QString proxyAuthorizationBasic () const
 
std::pair< QString, QString > proxyAuthorizationBasicPair () const
 
void pushHeader (const QString &field, const QString &value)
 
void pushHeader (const QString &field, const QStringList &values)
 
void pushRawHeader (const QString &field, const QString &value)
 
QString referer () const
 
void removeHeader (const QString &field)
 
QString server () const
 
QString setAuthorizationBasic (const QString &username, const QString &password)
 
void setCacheControl (const QString &value)
 
void setContentDisposition (const QString &contentDisposition)
 
void setContentDispositionAttachment (const QString &filename=QString())
 
void setContentEncoding (const QString &encoding)
 
void setContentLength (qint64 value)
 
void setContentType (const QString &contentType)
 
void setContentTypeCharset (const QString &charset)
 
QString setDateWithDateTime (const QDateTime &date)
 
void setETag (const QString &etag)
 
void setHeader (const QString &field, const QString &value)
 
void setHeader (const QString &field, const QStringList &values)
 
QString setLastModified (const QDateTime &lastModified)
 
void setLastModified (const QString &value)
 
void setProxyAuthenticate (const QString &value)
 
void setReferer (const QString &value)
 
void setServer (const QString &value)
 
void setWwwAuthenticate (const QString &value)
 
QString userAgent () const
 

Detailed Description

Definition at line 29 of file headers.h.

Constructor & Destructor Documentation

◆ Headers() [1/3]

Cutelyst::Headers::Headers ( )
default

Construct an empty header object.

◆ Headers() [2/3]

Headers::Headers ( const Headers other)

Constructs a copy of \pa other.

Definition at line 32 of file headers.cpp.

◆ Headers() [3/3]

Cutelyst::Headers::Headers ( std::initializer_list< std::pair< QString, QString > >  list)
inline

Construct a header from a std::initializer_list given by list.

Definition at line 46 of file headers.h.

Member Function Documentation

◆ authorization()

QString Headers::authorization ( ) const

This method is used to get an authorization header without any decoding.

Definition at line 349 of file headers.cpp.

Referenced by authorizationBasic(), and authorizationBasicPair().

◆ authorizationBasic()

QString Headers::authorizationBasic ( ) const

This method is used to get an authorization header that use the "Basic Authentication Scheme". It will return "username:password" as a single string value.

Definition at line 354 of file headers.cpp.

References authorization().

◆ authorizationBasicPair()

std::pair< QString, QString > Headers::authorizationBasicPair ( ) const

This method is used to get an authorization header that use the "Basic Authentication Scheme". It will return a pair of username and password respectively.

Definition at line 359 of file headers.cpp.

References authorization().

◆ clear()

void Cutelyst::Headers::clear ( )
inline

Clears all headers.

Definition at line 373 of file headers.h.

◆ connection()

QString Headers::connection ( ) const

Returns the 'Connection' header field that indicates how it should be handled after a request has been processed, like 'close'.

Definition at line 308 of file headers.cpp.

◆ contains()

bool Headers::contains ( const QString &  field)

Returns true if the header field is defined.

Definition at line 428 of file headers.cpp.

◆ contentDisposition()

QString Headers::contentDisposition ( ) const

The Content-Disposition header field indicates if the content is expected to be displayed inline in the browser, that is, as a Web page or as part of a Web page, or as an attachment, that is downloaded and saved locally

Definition at line 36 of file headers.cpp.

Referenced by setContentDisposition().

◆ contentEncoding()

QString Headers::contentEncoding ( ) const

The Content-Encoding header field is used as a modifier to the media type. When present, its value indicates what additional encoding mechanism has been applied to the resource.

Definition at line 60 of file headers.cpp.

◆ contentIsHtml()

bool Headers::contentIsHtml ( ) const

Returns TRUE if the Content-Type header field indicate that the content is some kind of HTML (including XHTML).

Definition at line 140 of file headers.cpp.

References contentType().

◆ contentIsJson()

bool Headers::contentIsJson ( ) const

Returns TRUE if the Content-Type header field indicate that the content is JSON.

Definition at line 163 of file headers.cpp.

◆ contentIsText()

bool Headers::contentIsText ( ) const

Returns TRUE if the Content-Type header field indicate that the content is textual.

Definition at line 135 of file headers.cpp.

◆ contentIsXHtml()

bool Headers::contentIsXHtml ( ) const

Returns TRUE if the Content-Type header field indicate that the content is XHTML.

Definition at line 148 of file headers.cpp.

References contentType().

◆ contentIsXml()

bool Headers::contentIsXml ( ) const

Returns TRUE if the Content-Type header field indicate that the content is XML.

Definition at line 155 of file headers.cpp.

References contentType().

◆ contentLength()

qint64 Headers::contentLength ( ) const

Returns the size in bytes of the message content

Definition at line 172 of file headers.cpp.

Referenced by Cutelyst::EngineRequest::finalizeHeaders().

◆ contentType()

QString Headers::contentType ( ) const

The Content-Type header field indicates the media type of the message content. E.g.: "text/html" The value returned will be converted to lower case, and potential parameters will be ignored. If there is no such header field, then the empty string is returned.

Definition at line 70 of file headers.cpp.

Referenced by contentIsHtml(), contentIsXHtml(), contentIsXml(), contentTypeCharset(), setContentType(), and setContentTypeCharset().

◆ contentTypeCharset()

QString Headers::contentTypeCharset ( ) const

Returns the upper-cased charset specified in the Content-Type header.

Definition at line 86 of file headers.cpp.

References contentType().

◆ data()

QHash<QString, QString> Cutelyst::Headers::data ( ) const
inline

Returns the internal structure of headers, to be used by Engine subclasses.

Definition at line 380 of file headers.h.

◆ date()

QDateTime Headers::date ( ) const

Returns the date header as QDateTime

Definition at line 196 of file headers.cpp.

Referenced by setDateWithDateTime().

◆ header() [1/2]

QString Headers::header ( const QString &  field) const

Returns the value associated with field

Definition at line 393 of file headers.cpp.

◆ header() [2/2]

QString Headers::header ( const QString &  field,
const QString &  defaultValue 
) const

Returns the value associated with field, if field is not set defaultValue is returned

Definition at line 398 of file headers.cpp.

◆ host()

QString Headers::host ( ) const

Returns the 'Host' header field used in request messages, containing information about which host the client would like to talk to, this is especially useful for building URIs and for VirtualHosts.

Definition at line 313 of file headers.cpp.

◆ ifMatch()

bool Headers::ifMatch ( const QString &  etag) const

Checks for If-Match header usually used on POST to avoid mid-air collisions, making sure the content has not changed while the client changes it. Returns true if the etag value matches the value between double quotes of the client header or if the client did not provide the If-Match header.

In case of false client should usually discard posted data and return status code of 412 - Response::PreconditionFailed

Definition at line 251 of file headers.cpp.

◆ ifModifiedSince() [1/2]

QString Headers::ifModifiedSince ( ) const

This header fields is used to make a request conditional. If the requested resource has (or has not) been modified since the time specified in this field, then the server will return a 304 Not Modified response instead of the document itself.

Definition at line 216 of file headers.cpp.

◆ ifModifiedSince() [2/2]

bool Headers::ifModifiedSince ( const QDateTime &  lastModified) const

Checks if Last-Modified's content has changed in comparison to the If-Modified-Since header.

Definition at line 241 of file headers.cpp.

References lastModified().

◆ ifModifiedSinceDateTime()

QDateTime Headers::ifModifiedSinceDateTime ( ) const

This header fields is used to make a request conditional. If the requested resource has (or has not) been modified since the time specified in this field, then the server will return a 304 Not Modified response instead of the document itself. This method parses the header and convert to QDateTime assuming the date is in GMT timezone.

Definition at line 221 of file headers.cpp.

◆ ifNoneMatch()

bool Headers::ifNoneMatch ( const QString &  etag) const

Checks for If-None-Match header to see if the client has the most recent version of a cached resource. Returns true if the etag value matches the value between double quotes of the client header.

In case of true client should usually return an empty body along with a status code of 304 - Response::NotModified.

Definition at line 262 of file headers.cpp.

◆ lastModified()

QString Headers::lastModified ( ) const

This header indicates the date and time at which the resource was last modified.

Definition at line 278 of file headers.cpp.

Referenced by ifModifiedSince(), and setLastModified().

◆ operator QVariant()

Cutelyst::Headers::operator QVariant ( ) const
inline

Returns this Header internal data as a QVariant for easiness with Q_PROPERTY.

Definition at line 425 of file headers.h.

◆ operator!=()

bool Cutelyst::Headers::operator!= ( const Headers other) const
inline

Compares if another Header object does not have the same data as this.

Definition at line 418 of file headers.h.

◆ operator=()

Headers& Cutelyst::Headers::operator= ( const Headers other)
inline

Assigns other to this Header and returns a reference to this Header.

Definition at line 402 of file headers.h.

◆ operator==()

bool Cutelyst::Headers::operator== ( const Headers other) const
inline

Compares if another Header object has the same data as this.

Definition at line 411 of file headers.h.

◆ operator[]() [1/2]

QString & Headers::operator[] ( const QString &  key)

Returns the value reference associated with key.

Definition at line 433 of file headers.cpp.

◆ operator[]() [2/2]

const QString Headers::operator[] ( const QString &  key) const

Returns the const value associated with key.

Definition at line 438 of file headers.cpp.

◆ proxyAuthorization()

QString Headers::proxyAuthorization ( ) const

A user agent that wishes to authenticate itself with a server or a proxy, may do so by including these headers.

Definition at line 378 of file headers.cpp.

Referenced by proxyAuthorizationBasic(), and proxyAuthorizationBasicPair().

◆ proxyAuthorizationBasic()

QString Headers::proxyAuthorizationBasic ( ) const

This method is used to get an authorization header that use the "Basic Authentication Scheme" but using the "Proxy-Authorization" header instead. It will return "username:password" as a single string value.

Definition at line 383 of file headers.cpp.

References proxyAuthorization().

◆ proxyAuthorizationBasicPair()

std::pair< QString, QString > Headers::proxyAuthorizationBasicPair ( ) const

This method is used to get an authorization header that use the "Basic Authentication Scheme" but using the "Proxy-Authorization" header instead. It will return a pair of username and password respectively.

Definition at line 388 of file headers.cpp.

References proxyAuthorization().

◆ pushHeader() [1/2]

void Headers::pushHeader ( const QString &  field,
const QString &  value 
)

Appends the header field to values

Definition at line 413 of file headers.cpp.

Referenced by Cutelyst::EngineRequest::finalizeCookies().

◆ pushHeader() [2/2]

void Headers::pushHeader ( const QString &  field,
const QStringList &  values 
)

This method appends a header to internal data normalizing the key.

Definition at line 418 of file headers.cpp.

◆ pushRawHeader()

void Cutelyst::Headers::pushRawHeader ( const QString &  field,
const QString &  value 
)
inline

This method directly inserts a Header in it's properly form which is field in upper case form with underscores instead of dashes, so 'Content-Type' becomes 'CONTENT_TYPE' like CGI does, this method should be used only by Engines to get faster performance and avoiding normalization.

Definition at line 433 of file headers.h.

◆ referer()

QString Headers::referer ( ) const

Used to specify the address (URI) of the document from which the requested resource address was obtained.

Definition at line 323 of file headers.cpp.

◆ removeHeader()

void Headers::removeHeader ( const QString &  field)

This method removes a header identified by field.

Definition at line 423 of file headers.cpp.

◆ server()

QString Headers::server ( ) const

Returns the server header field contains information about the software being used by the originating server program handling the request.

Definition at line 298 of file headers.cpp.

◆ setAuthorizationBasic()

QString Headers::setAuthorizationBasic ( const QString &  username,
const QString &  password 
)

This method is used to set an authorization header that use the "Basic Authentication Scheme". It won't set the values if username contains a colon ':'.

Definition at line 364 of file headers.cpp.

◆ setCacheControl()

void Headers::setCacheControl ( const QString &  value)

Defines the Cache-Control header

Definition at line 41 of file headers.cpp.

◆ setContentDisposition()

void Headers::setContentDisposition ( const QString &  contentDisposition)

Defines the Content-Disposition header

See also
contentDisposition()

Definition at line 46 of file headers.cpp.

References contentDisposition().

Referenced by setContentDispositionAttachment().

◆ setContentDispositionAttachment()

void Headers::setContentDispositionAttachment ( const QString &  filename = QString())

Defines the Content-Disposition header as type attachment and the optional filename parameter

See also
contentDisposition()

Definition at line 51 of file headers.cpp.

References setContentDisposition().

◆ setContentEncoding()

void Headers::setContentEncoding ( const QString &  encoding)

Defines the Content-Encoding header

See also
contentEncoding()

Definition at line 65 of file headers.cpp.

◆ setContentLength()

void Headers::setContentLength ( qint64  value)

Defines the size in bytes of the message content

Definition at line 181 of file headers.cpp.

Referenced by Cutelyst::EngineRequest::finalizeHeaders().

◆ setContentType()

void Headers::setContentType ( const QString &  contentType)

Defines the Content-Encoding header

See also
contentType()

Definition at line 81 of file headers.cpp.

References contentType().

◆ setContentTypeCharset()

void Headers::setContentTypeCharset ( const QString &  charset)

The Content-Type header field indicates the media type of the message content. this defines the charset of the content-type

Definition at line 102 of file headers.cpp.

References contentType().

◆ setDateWithDateTime()

QString Headers::setDateWithDateTime ( const QDateTime &  date)

Defines the header that represents the date and time at which the message was originated

Definition at line 186 of file headers.cpp.

References date().

◆ setETag()

void Headers::setETag ( const QString &  etag)

Sets the ETag header in strong form by not prepending a 'W/' (weak etag) This method will place the etag value between double quotes, like: ETag: "33a64df551425fcc55e4d42a148795d9f25f89d4"

Definition at line 273 of file headers.cpp.

◆ setHeader() [1/2]

void Headers::setHeader ( const QString &  field,
const QString &  value 
)

Sets the header field to value

Definition at line 403 of file headers.cpp.

Referenced by setHeader().

◆ setHeader() [2/2]

void Headers::setHeader ( const QString &  field,
const QStringList &  values 
)

Sets the header field to the list of values

Definition at line 408 of file headers.cpp.

References setHeader().

◆ setLastModified() [1/2]

QString Headers::setLastModified ( const QDateTime &  lastModified)

Defines the date and time at which the resource was last modified. This method takes a QDateTime and write it in RFC 822 and GMT timezone.

Definition at line 288 of file headers.cpp.

References lastModified(), and setLastModified().

◆ setLastModified() [2/2]

void Headers::setLastModified ( const QString &  value)

Defines the date and time at which the resource was last modified.

Definition at line 283 of file headers.cpp.

Referenced by setLastModified().

◆ setProxyAuthenticate()

void Headers::setProxyAuthenticate ( const QString &  value)

This header must be included in a 407 Proxy Authentication Required response.

Definition at line 344 of file headers.cpp.

◆ setReferer()

void Headers::setReferer ( const QString &  value)

Sets the referrer (Referer) header. This method removes the fragment from the given URI if it is present, as mandated by RFC2616. Note that the removal does not happen automatically if using the setHeader() method to set the referrer

Definition at line 328 of file headers.cpp.

◆ setServer()

void Headers::setServer ( const QString &  value)

Defines the server header field contains information about the software being used by the originating server program handling the request.

Definition at line 303 of file headers.cpp.

◆ setWwwAuthenticate()

void Headers::setWwwAuthenticate ( const QString &  value)

This header must be included as part of a 401 Unauthorized response. The field value consist of a challenge that indicates the authentication scheme and parameters applicable to the requested URI.

Definition at line 339 of file headers.cpp.

◆ userAgent()

QString Headers::userAgent ( ) const

Returns the header field used in request messages, containing information about the user agent originating the request.

Definition at line 318 of file headers.cpp.