cutelyst 4.3.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
|
Send network requests to other endpoints. More...
Functions | |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | deleteResource (const QNetworkRequest &request) |
CUTELYST_PLUGIN_USERAGENT_EXPORT void | forwardAsync (Context *c, const QUrl &destination) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | forwardRequest (Request *request, const QUrl &destination) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | forwardRequestResponse (Context *c, const QUrl &destination) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | get (const QNetworkRequest &request) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | head (const QNetworkRequest &request) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkAccessManager * | networkAccessManager () |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | post (const QNetworkRequest &request, const QByteArray &data) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | post (const QNetworkRequest &request, QHttpMultiPart *multiPart) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | post (const QNetworkRequest &request, QIODevice *data) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | postJson (const QNetworkRequest &request, const QJsonDocument &doc) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | postJsonArray (const QNetworkRequest &request, const QJsonArray &array) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | postJsonObject (const QNetworkRequest &request, const QJsonObject &object) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | put (const QNetworkRequest &request, const QByteArray &data) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | put (const QNetworkRequest &request, QHttpMultiPart *multiPart) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | put (const QNetworkRequest &request, QIODevice *data) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | putJson (const QNetworkRequest &request, const QJsonDocument &doc) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | putJsonArray (const QNetworkRequest &request, const QJsonArray &array) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | putJsonObject (const QNetworkRequest &request, const QJsonObject &object) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | sendCustomRequest (const QNetworkRequest &request, const QByteArray &verb, const QByteArray &data) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | sendCustomRequest (const QNetworkRequest &request, const QByteArray &verb, QHttpMultiPart *multiPart) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | sendCustomRequest (const QNetworkRequest &request, const QByteArray &verb, QIODevice *data=nullptr) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | sendCustomRequestJson (const QNetworkRequest &request, const QByteArray &verb, const QJsonDocument &doc) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | sendCustomRequestJsonArray (const QNetworkRequest &request, const QByteArray &verb, const QJsonArray &array) |
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReply * | sendCustomRequestJsonObject (const QNetworkRequest &request, const QByteArray &verb, const QJsonObject &object) |
The UserAgent plugin provides access to a thread local network access manager object to perform network requests. It also has some convenience functions for often used data types like JSON.
See also the documentation for QNetworkAccessManager to learn more about sending network requests.
QNetworkReply * Cutelyst::UA::deleteResource | ( | const QNetworkRequest & | request | ) |
Sends a request to delete the resource identified by the URL of request.
Definition at line 60 of file useragent.cpp.
References QNetworkAccessManager::deleteResource().
This will forward your request to destination, handlying both request and response and it will also call detachAsync() and attachAsync().
Definition at line 211 of file useragent.cpp.
References Cutelyst::Context::attachAsync(), QNetworkReply::attribute(), QObject::connect(), Cutelyst::Context::detachAsync(), QNetworkReply::finished(), forwardRequest(), QNetworkRequest::HttpStatusCodeAttribute, Cutelyst::Headers::pushHeader(), QNetworkReply::RawHeaderPair, QNetworkReply::rawHeaderPairs(), Cutelyst::Context::request, Cutelyst::Context::response(), Cutelyst::Response::setBody(), Cutelyst::Response::setStatus(), and QVariant::toUInt().
QNetworkReply * Cutelyst::UA::forwardRequest | ( | Request * | request, |
const QUrl & | destination | ||
) |
This will forward your request to destination, the entire response processing should be done by your code.
Definition at line 175 of file useragent.cpp.
References Cutelyst::Request::body(), Cutelyst::Headers::data(), Cutelyst::Request::headers(), QUrl::host(), QUrl::port(), QUrl::scheme(), QNetworkAccessManager::sendCustomRequest(), QUrl::setHost(), QUrl::setPort(), QNetworkRequest::setRawHeader(), and QUrl::setScheme().
Referenced by forwardAsync(), and forwardRequestResponse().
QNetworkReply * Cutelyst::UA::forwardRequestResponse | ( | Context * | c, |
const QUrl & | destination | ||
) |
This will forward your request to destination, handlying both request and response but it will not call detachAsync() and attachAsync().
Do not call deleteLater on the returned object as it will be set as the response body.
Definition at line 195 of file useragent.cpp.
References QNetworkReply::attribute(), QObject::connect(), QNetworkReply::finished(), forwardRequest(), QNetworkRequest::HttpStatusCodeAttribute, Cutelyst::Headers::pushHeader(), QNetworkReply::RawHeaderPair, QNetworkReply::rawHeaderPairs(), Cutelyst::Context::request, Cutelyst::Context::response(), Cutelyst::Response::setBody(), Cutelyst::Response::setStatus(), and QVariant::toUInt().
QNetworkReply * Cutelyst::UA::get | ( | const QNetworkRequest & | request | ) |
Posts a request to obtain the contents of the target request and returns a new QNetworkReply object opened for reading which emits the readyRead() signal whenever new data arrives.
The contents as well as associated headers will be downloaded
Definition at line 35 of file useragent.cpp.
References QNetworkAccessManager::get().
QNetworkReply * Cutelyst::UA::head | ( | const QNetworkRequest & | request | ) |
Posts a request to obtain the network headers for request and returns a new QNetworkReply object which will contain such headers.
The function is named after the HTTP request associated (HEAD).
Definition at line 30 of file useragent.cpp.
References QNetworkAccessManager::head().
QNetworkAccessManager * Cutelyst::UA::networkAccessManager | ( | ) |
Returns a pointer to the thread local network access manager object.
Definition at line 25 of file useragent.cpp.
QNetworkReply * Cutelyst::UA::post | ( | const QNetworkRequest & | request, |
const QByteArray & | data | ||
) |
This is an overloaded function.
Sends the contents of the data byte array to the destination specified by request.
Definition at line 45 of file useragent.cpp.
References QNetworkAccessManager::post().
QNetworkReply * Cutelyst::UA::post | ( | const QNetworkRequest & | request, |
QHttpMultiPart * | multiPart | ||
) |
This is an overloaded function.
Sends the contents of the multiPart message to the destination specified by request.
This can be used for sending MIME multipart messages over HTTP.
Definition at line 78 of file useragent.cpp.
References QNetworkAccessManager::post().
QNetworkReply * Cutelyst::UA::post | ( | const QNetworkRequest & | request, |
QIODevice * | data | ||
) |
Sends an HTTP POST request to the destination specified by request and returns a new QNetworkReply object opened for reading that will contain the reply sent by the server. The contents of the data device will be uploaded to the server.
data must be open for reading and must remain valid until the finished() signal is emitted for this reply.
Definition at line 40 of file useragent.cpp.
References QNetworkAccessManager::post().
QNetworkReply * Cutelyst::UA::postJson | ( | const QNetworkRequest & | request, |
const QJsonDocument & | doc | ||
) |
Sends the content of the JSON document doc to the destination specified by request using HTTP POST.
This will set the Content-Type
header to 'application/json'.
Definition at line 95 of file useragent.cpp.
References QJsonDocument::Compact, QNetworkRequest::ContentTypeHeader, QNetworkAccessManager::post(), QNetworkRequest::setHeader(), and QJsonDocument::toJson().
QNetworkReply * Cutelyst::UA::postJsonArray | ( | const QNetworkRequest & | request, |
const QJsonArray & | array | ||
) |
Sends the content of the JSON array to the destination specified by request using HTTP POST.
This will set the Content-Type
header to 'application/json'.
Definition at line 148 of file useragent.cpp.
References QJsonDocument::Compact, QNetworkRequest::ContentTypeHeader, QNetworkAccessManager::post(), and QNetworkRequest::setHeader().
QNetworkReply * Cutelyst::UA::postJsonObject | ( | const QNetworkRequest & | request, |
const QJsonObject & | object | ||
) |
Sends the content of the JSON object to the destination specified by request using HTTP POST.
This will set the Content-Type
header to 'application/json'.
Definition at line 121 of file useragent.cpp.
References QJsonDocument::Compact, QNetworkRequest::ContentTypeHeader, QNetworkAccessManager::post(), and QNetworkRequest::setHeader().
QNetworkReply * Cutelyst::UA::put | ( | const QNetworkRequest & | request, |
const QByteArray & | data | ||
) |
This is an overloaded function.
Sends the contents of the data byte array to the destination specified by request.
Definition at line 55 of file useragent.cpp.
References QNetworkAccessManager::put().
QNetworkReply * Cutelyst::UA::put | ( | const QNetworkRequest & | request, |
QHttpMultiPart * | multiPart | ||
) |
This is an overloaded function.
Sends the contents of the multiPart message to the destination specified by request.
This can be used for sending MIME multipart messages over HTTP
Definition at line 83 of file useragent.cpp.
References QNetworkAccessManager::post().
QNetworkReply * Cutelyst::UA::put | ( | const QNetworkRequest & | request, |
QIODevice * | data | ||
) |
Uploads the contents of data to the destination request and returns a new QNetworkReply object that will be open for reply.
data must be opened for reading when this function is called and must remain valid until the finished() signal is emitted for this reply.
Whether anything will be available for reading from the returned object is protocol dependent. For HTTP, the server may send a small HTML page indicating the upload was successful (or not). Other protocols will probably have content in their replies.
Definition at line 50 of file useragent.cpp.
References QNetworkAccessManager::put().
QNetworkReply * Cutelyst::UA::putJson | ( | const QNetworkRequest & | request, |
const QJsonDocument & | doc | ||
) |
Sends the content of the JSON document doc to the destination specified by request using HTTP PUT.
This will set the Content-Type
header to 'application/json'.
Definition at line 103 of file useragent.cpp.
References QJsonDocument::Compact, QNetworkRequest::ContentTypeHeader, QNetworkAccessManager::put(), QNetworkRequest::setHeader(), and QJsonDocument::toJson().
QNetworkReply * Cutelyst::UA::putJsonArray | ( | const QNetworkRequest & | request, |
const QJsonArray & | array | ||
) |
Sends the content of the JSON array to the destination specified by request using HTTP PUT.
This will set the Content-Type
header to 'application/json'.
Definition at line 156 of file useragent.cpp.
References QJsonDocument::Compact, QNetworkRequest::ContentTypeHeader, QNetworkAccessManager::put(), and QNetworkRequest::setHeader().
QNetworkReply * Cutelyst::UA::putJsonObject | ( | const QNetworkRequest & | request, |
const QJsonObject & | object | ||
) |
Sends the content of the JSON object obj to the destination specified by request using HTTP PUT.
This will set the Content-Type
header to 'application/json'.
Definition at line 129 of file useragent.cpp.
References QJsonDocument::Compact, QNetworkRequest::ContentTypeHeader, QNetworkAccessManager::put(), and QNetworkRequest::setHeader().
QNetworkReply * Cutelyst::UA::sendCustomRequest | ( | const QNetworkRequest & | request, |
const QByteArray & | verb, | ||
const QByteArray & | data | ||
) |
This is an overloaded function.
Sends the contents of the data byte array to the destination specified by request.
Definition at line 71 of file useragent.cpp.
References QNetworkAccessManager::sendCustomRequest().
QNetworkReply * Cutelyst::UA::sendCustomRequest | ( | const QNetworkRequest & | request, |
const QByteArray & | verb, | ||
QHttpMultiPart * | multiPart | ||
) |
This is an overloaded function.
Sends a custom request to the server identified by the URL of request.
Sends the contents of the multiPart message to the destination specified by request.
This can be used for sending MIME multipart messages for custom verbs.
Definition at line 88 of file useragent.cpp.
References QNetworkAccessManager::sendCustomRequest().
QNetworkReply * Cutelyst::UA::sendCustomRequest | ( | const QNetworkRequest & | request, |
const QByteArray & | verb, | ||
QIODevice * | data = nullptr |
||
) |
Sends a custom request to the server identified by the URL of request.
It is the user's responsibility to send a verb to the server that is valid according to the HTTP specification.
This method provides means to send verbs other than the common ones provided via get() or post() etc., for instance sending an HTTP OPTIONS command.
If data is not empty, the contents of the data device will be uploaded to the server; in that case, data must be open for reading and must remain valid until the finished() signal is emitted for this reply.
Definition at line 66 of file useragent.cpp.
References QNetworkAccessManager::sendCustomRequest().
Referenced by sendCustomRequestJson(), sendCustomRequestJsonArray(), and sendCustomRequestJsonObject().
QNetworkReply * Cutelyst::UA::sendCustomRequestJson | ( | const QNetworkRequest & | request, |
const QByteArray & | verb, | ||
const QJsonDocument & | doc | ||
) |
Sends the content of the JSON document doc to the destination specified by request using a custom verb.
This will set the Content-Type
header to 'application/json'.
Definition at line 111 of file useragent.cpp.
References QJsonDocument::Compact, QNetworkRequest::ContentTypeHeader, sendCustomRequest(), QNetworkRequest::setHeader(), and QJsonDocument::toJson().
QNetworkReply * Cutelyst::UA::sendCustomRequestJsonArray | ( | const QNetworkRequest & | request, |
const QByteArray & | verb, | ||
const QJsonArray & | array | ||
) |
Sends the content of the JSON array to the destination specified by request using a custom verb.
This will set the Content-Type
header to 'application/json'.
Definition at line 164 of file useragent.cpp.
References QJsonDocument::Compact, QNetworkRequest::ContentTypeHeader, sendCustomRequest(), and QNetworkRequest::setHeader().
QNetworkReply * Cutelyst::UA::sendCustomRequestJsonObject | ( | const QNetworkRequest & | request, |
const QByteArray & | verb, | ||
const QJsonObject & | object | ||
) |
Sends the content of the JSON object to the destination specified by request using a custom verb.
This will set the Content-Type
header to 'application/json'.
Definition at line 137 of file useragent.cpp.
References QJsonDocument::Compact, QNetworkRequest::ContentTypeHeader, sendCustomRequest(), and QNetworkRequest::setHeader().