|
cutelyst 4.0.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
|

Public Types | |
| enum | CloseCode { CloseCodeNormal , CloseCodeGoingAway , CloseCodeProtocolError , CloseCodeDatatypeNotSupported , CloseCodeReserved1004 , CloseCodeMissingStatusCode , CloseCodeAbnormalDisconnection , CloseCodeWrongDatatype , CloseCodePolicyViolated , CloseCodeTooMuchData , CloseCodeMissingExtension , CloseCodeBadOperation , CloseCodeTlsHandshakeFailed } |
| enum | HttpStatus { Continue , SwitchingProtocols , OK , Created , Accepted , NonAuthoritativeInformation , NoContent , ResetContent , PartialContent , MultiStatus , MultipleChoices , MovedPermanently , Found , SeeOther , NotModified , UseProxy , TemporaryRedirect , PermanentRedirect , BadRequest , Unauthorized , PaymentRequired , Forbidden , NotFound , MethodNotAllowed , NotAcceptable , ProxyAuthenticationRequired , RequestTimeout , Conflict , Gone , LengthRequired , PreconditionFailed , RequestEntityTooLarge , RequestURITooLong , UnsupportedMediaType , RequestedRangeNotSatisfiable , ExpectationFailed , InternalServerError , NotImplemented , BadGateway , ServiceUnavailable , GatewayTimeout , HTTPVersionNotSupported , BandwidthLimitExceeded } |
Public Member Functions | |
| QByteArray & | body () |
| QIODevice * | bodyDevice () const noexcept |
| QByteArray | contentEncoding () const noexcept |
| qint64 | contentLength () const |
| QByteArray | contentType () const |
| QByteArray | contentTypeCharset () const |
| QVariant | cookie (const QByteArray &name) const |
| QList< QNetworkCookie > | cookies () const |
| bool | hasBody () const noexcept |
| QByteArray | header (const QByteArray &field) const noexcept |
| Headers & | headers () noexcept |
| bool | isFinalizedHeaders () const noexcept |
| bool | isSequential () const noexcept override |
| QUrl | location () const noexcept |
| void | redirect (const QString &url, quint16 status=Found) |
| void | redirect (const QUrl &url, quint16 status=Found) |
| void | redirectSafe (const QUrl &url, const QUrl &fallback) |
| int | removeCookies (const QByteArray &name) |
| void | setBody (const QByteArray &body) |
| void | setBody (const QString &body) |
| void | setBody (QIODevice *body) |
| void | setBody (QStringView body) |
| void | setContentEncoding (const QByteArray &encoding) |
| void | setContentLength (qint64 length) |
| void | setContentType (const QByteArray &type) |
| void | setCookie (const QNetworkCookie &cookie) |
| void | setCookies (const QList< QNetworkCookie > &cookies) |
| void | setHeader (const QByteArray &key, const QByteArray &value) |
| void | setJsonArrayBody (const QJsonArray &array) |
| void | setJsonBody (const QByteArray &json) |
| void | setJsonBody (QStringView json) |
| void | setJsonObjectBody (const QJsonObject &obj) |
| void | setStatus (quint16 status) noexcept |
| qint64 | size () const noexcept override |
| quint16 | status () const noexcept |
| bool | webSocketBinaryMessage (const QByteArray &message) |
| Sends a WebSocket binary message. | |
| bool | webSocketClose (quint16 code=Response::CloseCodeNormal, const QString &reason={}) |
| Sends a WebSocket close frame, with both optional close code and a string reason. More... | |
| bool | webSocketHandshake (const QByteArray &key={}, const QByteArray &origin={}, const QByteArray &protocol={}) |
| Sends the websocket handshake, if no parameters are defined it will use header data. More... | |
| bool | webSocketPing (const QByteArray &payload={}) |
| Sends a WebSocket ping with an optional payload limited to 125 bytes, which will be truncated if larger. More... | |
| bool | webSocketTextMessage (const QString &message) |
| Sends a WebSocket text message. | |
Protected Member Functions | |
| Response (const Headers &defaultHeaders, EngineRequest *conn=nullptr) | |
| virtual qint64 | readData (char *data, qint64 maxlen) override |
| virtual qint64 | writeData (const char *data, qint64 len) override |
Friends | |
| class | Application |
| class | Context |
| class | ContextPrivate |
| class | Engine |
| class | EngineConnection |
Definition at line 20 of file response.h.
This enum type specifies the status response to be sent to the client
Definition at line 74 of file response.h.
This enum type specifies the status response to be sent to the client
Definition at line 26 of file response.h.
|
overridevirtual |
Definition at line 60 of file response.cpp.
|
explicitprotected |
Constructs a Response object, for this engine request and defaultHeaders.
Definition at line 19 of file response.cpp.
| QByteArray & Response::body | ( | ) |
This function returns a reference to a QByteArray which implicity sets the body device to a QBuffer, even if one was already set.
Definition at line 85 of file response.cpp.
Referenced by Cutelyst::EngineRequest::finalizeBody(), and setBody().
|
noexcept |
Returns the body IO device (if any) of this response.
Definition at line 96 of file response.cpp.
Referenced by Cutelyst::EngineRequest::finalizeBody().
|
noexcept |
Short for headers().contentEncoding();
Definition at line 139 of file response.cpp.
| qint64 Response::contentLength | ( | ) | const |
Short for headers().contentLength();
Definition at line 156 of file response.cpp.
| QByteArray Response::contentType | ( | ) | const |
Short for headers().contentType();
Definition at line 173 of file response.cpp.
Referenced by Cutelyst::RenderView::doExecute().
| QByteArray Response::contentTypeCharset | ( | ) | const |
Short for headers().contentTypeCharset();
Definition at line 179 of file response.cpp.
| QVariant Response::cookie | ( | const QByteArray & | name | ) | const |
Returns the first QNetworkCookie matching the name or a null QVariant if not found
Definition at line 185 of file response.cpp.
Referenced by setCookie(), and setCookies().
| QList< QNetworkCookie > Response::cookies | ( | ) | const |
Returns a list of all cookies set
Definition at line 191 of file response.cpp.
Referenced by Cutelyst::EngineRequest::finalizeCookies(), and setCookies().
|
noexcept |
Returns true if a body device has been defined as QByteArray or QIODevice or write() was called and it's on chunked mode
Definition at line 78 of file response.cpp.
Referenced by Cutelyst::RenderView::doExecute().
|
noexcept |
|
noexcept |
Returns a reference to the response headers class
Referenced by Cutelyst::EngineRequest::finalizeCookies(), and Cutelyst::EngineRequest::finalizeHeaders().
|
noexcept |
Returns if Headers are finalized (sent to the client)
|
overridenoexcept |
Writing to user-agent is always sequential
|
noexcept |
Returns the HTTP location set by the redirect
Referenced by redirect().
|
overrideprotectedvirtual |
Reimplemented from QIODevice::readData().
Definition at line 25 of file response.cpp.
| void Cutelyst::Response::redirect | ( | const QString & | url, |
| quint16 | status = Found |
||
| ) |
Causes the response to redirect to the specified URL. The default status is 302. This is a convenience method that sets the Location header to the redirect destination, and then sets the response status. You will want to return false or c->detach() to interrupt the normal processing flow if you want the redirect to occur straight away.
| void Response::redirect | ( | const QUrl & | url, |
| quint16 | status = Found |
||
| ) |
Causes the response to redirect to the specified URL. The default status is 302. This is a convenience method that sets the Location header to the redirect destination, and then sets the response status. You will want to return false or c->detach() to interrupt the normal processing flow if you want the redirect to occur straight away.
Definition at line 217 of file response.cpp.
References location(), setBody(), and status().
Referenced by Cutelyst::LangSelect::fromPath().
| void Cutelyst::Response::redirectSafe | ( | const QUrl & | url, |
| const QUrl & | fallback | ||
| ) |
Open Redirect Vulnerability is when you get an user provided URL and redirect to it without checking if it's safe.
This can be used on login forms that receive some "redir" parameter that once logged in allows the user to go straight to that page instead of some home page.
It's then possible to receive a link like http://example.com/login?redir=http://exemple.com/login notice how both domain names are similar for malicious porpuses, once logged in it redirects to a similar login page that will pretent the auth didn't work, user might then type their credentials on that page.
This method validades that the url scheme, domain name and port are the same of the request to your server if it isn't it will send the user to fallback url that you know it's safe. If you need to redirect the user to some other domain/port validate the URL manually an use the regular
| int Response::removeCookies | ( | const QByteArray & | name | ) |
Removes all cookies that matches name, returning the number of cookies removed
Definition at line 211 of file response.cpp.
| void Response::setBody | ( | const QByteArray & | body | ) |
Sets a QByteArray as the response body, content length will be automatically set to it's size.
Definition at line 116 of file response.cpp.
References body().
|
inline |
Sets a QString as the response body, the output will be UTF-8 and content length will be automatically set to it's size.
Definition at line 392 of file response.h.
References setBody().
| void Response::setBody | ( | QIODevice * | body | ) |
Sets an IO device as the response body, the open mode must be at least QIODevice::ReadOnly. This function takes ownership of your device deleting after the request has completed
Definition at line 102 of file response.cpp.
References body().
Referenced by Cutelyst::EngineRequest::finalizeError(), redirect(), Cutelyst::CuteleeView::render(), and setBody().
|
inline |
Sets a QString as the response body, the output will be UTF-8 and content length will be automatically set to it's size.
Definition at line 397 of file response.h.
References setBody().
| void Cutelyst::Response::setContentEncoding | ( | const QByteArray & | encoding | ) |
Short for headers().setContentEncoding(encoding);
Definition at line 145 of file response.cpp.
| void Response::setContentLength | ( | qint64 | length | ) |
Short for headers().setContentLength(length);
Definition at line 162 of file response.cpp.
|
inline |
Short for headers().setContentType(type);
Definition at line 203 of file response.h.
Referenced by Cutelyst::RenderView::doExecute(), Cutelyst::EngineRequest::finalizeError(), and Cutelyst::ViewJson::render().
| void Response::setCookie | ( | const QNetworkCookie & | cookie | ) |
Defines a QNetworkCookie to be sent to the user-agent, if a previous cookie->name() was set it will be replaced
Definition at line 197 of file response.cpp.
References cookie().
| void Response::setCookies | ( | const QList< QNetworkCookie > & | cookies | ) |
Defines a list of QNetworkCookie to be sent to the user-agent, all previous matches to cookie->name() will be preserved.
Definition at line 203 of file response.cpp.
| void Cutelyst::Response::setHeader | ( | const QByteArray & | key, |
| const QByteArray & | value | ||
| ) |
Shortcut headers().setHeader()
Referenced by Cutelyst::ViewJson::render().
| void Response::setJsonArrayBody | ( | const QJsonArray & | array | ) |
Sets a QJsonArray on a QJsonDocument as the response body, using toJson(QJsonDocument::Compact) output and setting content-type to application/json.
Definition at line 134 of file response.cpp.
References setJsonBody().
| void Response::setJsonBody | ( | const QByteArray & | json | ) |
Sets a JSON string as the response body, this method is provided for convenience as it sets the content-type to application/json.
Definition at line 122 of file response.cpp.
|
inline |
Sets a JSON string as the response body, this method is provided for convenience as it sets the content-type to application/json.
Definition at line 402 of file response.h.
References setJsonBody().
Referenced by setJsonArrayBody(), setJsonBody(), and setJsonObjectBody().
| void Response::setJsonObjectBody | ( | const QJsonObject & | obj | ) |
Sets a QJsonObject on a QJsonDocument as the response body, using toJson(QJsonDocument::Compact) output and setting content-type to application/json.
Definition at line 129 of file response.cpp.
References setJsonBody().
|
noexcept |
Sets the response code status
Definition at line 72 of file response.cpp.
Referenced by Cutelyst::RenderView::doExecute(), and Cutelyst::EngineRequest::finalizeError().
|
overridenoexcept |
Reimplemented from QIODevice::readData().
Referenced by Cutelyst::EngineRequest::finalizeHeaders().
|
noexcept |
The current response code status
Definition at line 66 of file response.cpp.
Referenced by Cutelyst::RenderView::doExecute(), Cutelyst::EngineRequest::finalizeHeaders(), and redirect().
| bool Cutelyst::Response::webSocketClose | ( | quint16 | code = Response::CloseCodeNormal, |
| const QString & | reason = {} |
||
| ) |
| bool Cutelyst::Response::webSocketHandshake | ( | const QByteArray & | key = {}, |
| const QByteArray & | origin = {}, |
||
| const QByteArray & | protocol = {} |
||
| ) |
Returns true in case of success, false otherwise, which can be due missing support on the engine or missing the appropriate headers.
| bool Cutelyst::Response::webSocketPing | ( | const QByteArray & | payload = {} | ) |
|
overrideprotectedvirtual |
Writes data to the response body, this will flush all response headers first and will enter in chunked mode if Transfer-Encoding header is set to chunked or if no content length is set and status is not 1xx or 204 (NoContent) or 304 (NotModified)
Definition at line 32 of file response.cpp.
|
friend |
Definition at line 385 of file response.h.
|
friend |
Definition at line 388 of file response.h.
|
friend |
Definition at line 389 of file response.h.
|
friend |
Definition at line 386 of file response.h.
|
friend |
Definition at line 387 of file response.h.