![]() |
cutelyst 5.0.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
|
Container for HTTP headers. More...
#include <Cutelyst/Headers>
Classes | |
struct | Authorization |
struct | HeaderKeyValue |
Headers is a container for HTTP headers that also implements helper methods to set and get specific headers.
|
defaultnoexcept |
Construct an empty Header object.
|
noexcept |
Constructs a copy of other.
Definition at line 29 of file headers.cpp.
|
inline |
|
noexcept |
This method is used to get an authorization header without any decoding.
Definition at line 337 of file headers.cpp.
References header().
Referenced by authorizationBasic(), authorizationBasicObject(), and authorizationBearer().
QByteArray 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().
Headers::Authorization Headers::authorizationBasicObject | ( | ) | 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().
QByteArray Headers::authorizationBearer | ( | ) | const |
This method is used to get an authorization token
Definition at line 342 of file headers.cpp.
References authorization(), and QByteArray::mid().
|
inline |
|
noexcept |
Returns the 'Connection' header field that indicates how it should be handled after a request has been processed, like 'close'.
Definition at line 296 of file headers.cpp.
References header().
|
noexcept |
Returns true
if the header field specified by key is defined.
Definition at line 481 of file headers.cpp.
Referenced by Cutelyst::ViewJson::render().
|
noexcept |
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 34 of file headers.cpp.
References header().
Referenced by setContentDisposition().
|
noexcept |
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 58 of file headers.cpp.
References header().
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 135 of file headers.cpp.
References QByteArray::compare(), and contentType().
bool Headers::contentIsJson | ( | ) | const |
Returns true
if the Content-Type header field indicate that the content is JSON.
Definition at line 155 of file headers.cpp.
References header().
bool Headers::contentIsText | ( | ) | const |
Returns true
if the Content-Type header field indicate that the content is textual.
Definition at line 130 of file headers.cpp.
References header(), and QByteArray::startsWith().
bool Headers::contentIsXHtml | ( | ) | const |
Returns true
if the Content-Type header field indicate that the content is XHTML.
Definition at line 142 of file headers.cpp.
References QByteArray::compare(), and contentType().
bool Headers::contentIsXml | ( | ) | const |
Returns true
if the Content-Type header field indicate that the content is XML.
Definition at line 149 of file headers.cpp.
References QByteArray::compare(), contentType(), and QByteArray::endsWith().
qint64 Headers::contentLength | ( | ) | const |
Returns the size in bytes of the message content
Definition at line 164 of file headers.cpp.
References header().
QByteArray 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 68 of file headers.cpp.
References header(), QByteArray::indexOf(), QByteArray::isEmpty(), QByteArray::mid(), and QByteArray::toLower().
Referenced by contentIsHtml(), contentIsXHtml(), contentIsXml(), and setContentType().
QByteArray Headers::contentTypeCharset | ( | ) | const |
Returns the upper-cased charset specified in the Content-Type header.
Definition at line 82 of file headers.cpp.
References header(), QByteArray::indexOf(), QByteArray::isEmpty(), QByteArray::mid(), QByteArray::toUpper(), and QByteArray::trimmed().
|
inline |
Returns the internal structure of headers, to be used by Engine subclasses.
Definition at line 420 of file headers.h.
Referenced by Cutelyst::UA::forwardRequest(), Cutelyst::ProtoRequestFastCGI::writeHeaders(), and Cutelyst::ProtoRequestHttp::writeHeaders().
QDateTime Headers::date | ( | ) | const |
Returns the Date header as QDateTime
Definition at line 188 of file headers.cpp.
References QLocale::c(), QString::fromLatin1(), header(), QDateTime::setTimeSpec(), QLocale::toDateTime(), and Qt::UTC.
Referenced by setDateWithDateTime().
|
noexcept |
Returns the value associated with key
Definition at line 393 of file headers.cpp.
Referenced by authorization(), connection(), contentDisposition(), contentEncoding(), contentIsJson(), contentIsText(), contentLength(), contentType(), contentTypeCharset(), date(), headerAsString(), host(), ifMatch(), ifModifiedSince(), ifModifiedSince(), ifModifiedSinceDateTime(), ifNoneMatch(), lastModified(), proxyAuthorization(), referer(), server(), and userAgent().
|
noexcept |
Returns the value associated with key
, if field is not set defaultValue
is returned
Definition at line 406 of file headers.cpp.
QString Headers::headerAsString | ( | QAnyStringView | key | ) | const |
Returns the value associated with key
from latin1
Definition at line 401 of file headers.cpp.
References QString::fromLatin1(), and header().
QString Headers::headerAsString | ( | QAnyStringView | key, |
const QString & | defaultValue | ||
) | const |
Returns the value associated with key
from latin1, if field is not set defaultValue
is returned
Definition at line 414 of file headers.cpp.
References QString::fromLatin1().
QByteArrayList Headers::headers | ( | QAnyStringView | key | ) | const |
Returns all values associated with key
Definition at line 422 of file headers.cpp.
References QList::append().
QStringList Headers::headersAsStrings | ( | QAnyStringView | key | ) | const |
Returns all values associated with key
Definition at line 431 of file headers.cpp.
References QList::append(), and QString::fromLatin1().
|
noexcept |
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 301 of file headers.cpp.
References header().
bool Headers::ifMatch | ( | QAnyStringView | 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 240 of file headers.cpp.
References header(), and QAnyStringView::sliced().
|
noexcept |
This header field 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 206 of file headers.cpp.
References header().
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 229 of file headers.cpp.
References QLocale::c(), header(), lastModified(), QString::toLatin1(), and QLocale::toString().
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 211 of file headers.cpp.
References QLocale::c(), QString::fromLatin1(), header(), QDateTime::setTimeSpec(), QLocale::toDateTime(), and Qt::UTC.
bool Headers::ifNoneMatch | ( | QAnyStringView | 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 251 of file headers.cpp.
References header(), and QAnyStringView::sliced().
QByteArrayList Headers::keys | ( | ) | const |
Definition at line 487 of file headers.cpp.
|
noexcept |
This header indicates the date and time at which the resource was last modified.
Definition at line 267 of file headers.cpp.
References header().
Referenced by ifModifiedSince(), and setLastModified().
|
noexcept |
Compares if other has the same data as this.
Definition at line 509 of file headers.cpp.
|
noexcept |
Returns the value associated with key.
Definition at line 504 of file headers.cpp.
|
noexcept |
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.
References header().
Referenced by proxyAuthorizationBasic(), and proxyAuthorizationBasicObject().
QByteArray 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().
Headers::Authorization Headers::proxyAuthorizationBasicObject | ( | ) | 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().
void Headers::pushHeader | ( | const QByteArray & | key, |
const QByteArray & | value | ||
) |
Appends the header field to values
Definition at line 464 of file headers.cpp.
Referenced by Cutelyst::EngineRequest::finalizeCookies(), Cutelyst::UA::forwardAsync(), and Cutelyst::UA::forwardRequestResponse().
void Headers::pushHeader | ( | const QByteArray & | key, |
const QByteArrayList & | values | ||
) |
This method appends a header to internal data normalizing the key.
Definition at line 469 of file headers.cpp.
References QByteArrayList::join().
|
noexcept |
Used to specify the address (URI) of the document from which the requested resource address was obtained.
Definition at line 311 of file headers.cpp.
References header().
void Headers::removeHeader | ( | QAnyStringView | key | ) |
This method removes a header identified by field
.
Definition at line 474 of file headers.cpp.
References Qt::CaseInsensitive, and QAnyStringView::compare().
Referenced by setContentTypeCharset().
|
noexcept |
Returns the server header field contains information about the software being used by the originating server program handling the request.
Definition at line 286 of file headers.cpp.
References header().
QByteArray 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.
References QString::contains(), setHeader(), QByteArray::toBase64(), and QString::toLatin1().
void Headers::setCacheControl | ( | const QByteArray & | value | ) |
Sets the value for the Cache-Control header.
Definition at line 39 of file headers.cpp.
References setHeader().
void Headers::setContentDisposition | ( | const QByteArray & | contentDisposition | ) |
Sets the value for the Content-Disposition header to contentDisposition.
Definition at line 44 of file headers.cpp.
References contentDisposition(), and setHeader().
Referenced by setContentDispositionAttachment().
void Headers::setContentDispositionAttachment | ( | const QByteArray & | filename = {} | ) |
Sets the Content-Disposition header as type attachment and sets the filename as optional filename parameter.
Definition at line 49 of file headers.cpp.
References QByteArray::isEmpty(), and setContentDisposition().
void Headers::setContentEncoding | ( | const QByteArray & | encoding | ) |
Sets the Content-Encoding header to encoding.
Definition at line 63 of file headers.cpp.
References setHeader().
void Headers::setContentLength | ( | qint64 | value | ) |
Sets the size in bytes of the message content.
Definition at line 173 of file headers.cpp.
References QByteArray::number(), and setHeader().
Referenced by Cutelyst::EngineRequest::finalizeHeaders().
void Headers::setContentType | ( | const QByteArray & | contentType | ) |
Sets the value for the Content-Type header to contentType.
Definition at line 77 of file headers.cpp.
References contentType(), and setHeader().
Referenced by setContentTypeCharset().
void Headers::setContentTypeCharset | ( | const QByteArray & | charset | ) |
Set the optional charset parameter of the Content-Type header field to charset.
Definition at line 97 of file headers.cpp.
References QByteArray::append(), QByteArray::indexOf(), QByteArray::isEmpty(), QByteArray::lastIndexOf(), QByteArray::length(), QByteArray::remove(), removeHeader(), QByteArray::replace(), and setContentType().
QByteArray Headers::setDateWithDateTime | ( | const QDateTime & | date | ) |
Sets the Date header that represents the date and time at which the message was originated.
Definition at line 178 of file headers.cpp.
References QLocale::c(), date(), setHeader(), QString::toLatin1(), QLocale::toString(), and QDateTime::toUTC().
void Headers::setETag | ( | const QByteArray & | 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 262 of file headers.cpp.
References setHeader().
void Headers::setHeader | ( | const QByteArray & | field, |
const QByteArrayList & | values | ||
) |
Sets the header field to the list of values
Definition at line 459 of file headers.cpp.
References QByteArrayList::join(), and setHeader().
void Headers::setHeader | ( | const QByteArray & | key, |
const QByteArray & | value | ||
) |
Sets the header field to value
Definition at line 440 of file headers.cpp.
References Qt::CaseInsensitive, and QByteArray::compare().
Referenced by setAuthorizationBasic(), setCacheControl(), setContentDisposition(), setContentEncoding(), setContentLength(), setContentType(), setDateWithDateTime(), setETag(), setHeader(), setLastModified(), setProxyAuthenticate(), setReferer(), setServer(), and setWwwAuthenticate().
void Headers::setLastModified | ( | const QByteArray & | value | ) |
Defines the date and time at which the resource was last modified.
Definition at line 272 of file headers.cpp.
References setHeader().
Referenced by setLastModified().
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 277 of file headers.cpp.
References QLocale::c(), lastModified(), setLastModified(), and QLocale::toString().
void Headers::setProxyAuthenticate | ( | const QByteArray & | value | ) |
This header must be included in a 407 Proxy Authentication Required response.
Definition at line 332 of file headers.cpp.
References setHeader().
void Headers::setReferer | ( | const QByteArray & | 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 316 of file headers.cpp.
References QByteArray::indexOf(), QByteArray::mid(), and setHeader().
void Headers::setServer | ( | const QByteArray & | value | ) |
Defines the server header field contains information about the software being used by the originating server program handling the request.
Definition at line 291 of file headers.cpp.
References setHeader().
void Headers::setWwwAuthenticate | ( | const QByteArray & | 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 327 of file headers.cpp.
References setHeader().
|
noexcept |
Returns the header field used in request messages, containing information about the user agent originating the request.
Definition at line 306 of file headers.cpp.
References header().