cutelyst 4.3.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
Cutelyst::UA Namespace Reference

Send network requests to other endpoints. More...

Functions

CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplydeleteResource (const QNetworkRequest &request)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT void forwardAsync (Context *c, const QUrl &destination)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplyforwardRequest (Request *request, const QUrl &destination)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplyforwardRequestResponse (Context *c, const QUrl &destination)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplyget (const QNetworkRequest &request)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplyhead (const QNetworkRequest &request)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkAccessManagernetworkAccessManager ()
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplypost (const QNetworkRequest &request, const QByteArray &data)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplypost (const QNetworkRequest &request, QHttpMultiPart *multiPart)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplypost (const QNetworkRequest &request, QIODevice *data)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplypostJson (const QNetworkRequest &request, const QJsonDocument &doc)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplypostJsonArray (const QNetworkRequest &request, const QJsonArray &array)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplypostJsonObject (const QNetworkRequest &request, const QJsonObject &object)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplyput (const QNetworkRequest &request, const QByteArray &data)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplyput (const QNetworkRequest &request, QHttpMultiPart *multiPart)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplyput (const QNetworkRequest &request, QIODevice *data)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplyputJson (const QNetworkRequest &request, const QJsonDocument &doc)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplyputJsonArray (const QNetworkRequest &request, const QJsonArray &array)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplyputJsonObject (const QNetworkRequest &request, const QJsonObject &object)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplysendCustomRequest (const QNetworkRequest &request, const QByteArray &verb, const QByteArray &data)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplysendCustomRequest (const QNetworkRequest &request, const QByteArray &verb, QHttpMultiPart *multiPart)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplysendCustomRequest (const QNetworkRequest &request, const QByteArray &verb, QIODevice *data=nullptr)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplysendCustomRequestJson (const QNetworkRequest &request, const QByteArray &verb, const QJsonDocument &doc)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplysendCustomRequestJsonArray (const QNetworkRequest &request, const QByteArray &verb, const QJsonArray &array)
 
CUTELYST_PLUGIN_USERAGENT_EXPORT QNetworkReplysendCustomRequestJsonObject (const QNetworkRequest &request, const QByteArray &verb, const QJsonObject &object)
 

Detailed Description

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.

Include file
#include <Cutelyst/Plugins/UserAgent>
Logging category
cutelyst.useragent
Logging with Cutelyst

Function Documentation

◆ deleteResource()

QNetworkReply * Cutelyst::UA::deleteResource ( const QNetworkRequest request)

Sends a request to delete the resource identified by the URL of request.

Note
This feature is currently available for HTTP only, performing an HTTP DELETE request.

Definition at line 60 of file useragent.cpp.

References QNetworkAccessManager::deleteResource().

◆ forwardAsync()

◆ forwardRequest()

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().

◆ 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().

◆ get()

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().

◆ head()

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().

◆ networkAccessManager()

QNetworkAccessManager * Cutelyst::UA::networkAccessManager ( )

Returns a pointer to the thread local network access manager object.

Definition at line 25 of file useragent.cpp.

◆ post() [1/3]

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().

◆ post() [2/3]

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().

◆ post() [3/3]

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.

Note
Sending a POST request on protocols other than HTTP and HTTPS is undefined and will probably fail.

Definition at line 40 of file useragent.cpp.

References QNetworkAccessManager::post().

◆ postJson()

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().

◆ postJsonArray()

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().

◆ postJsonObject()

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().

◆ put() [1/3]

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().

◆ put() [2/3]

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().

◆ put() [3/3]

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.

Note
For HTTP, this request will send a PUT request, which most servers do not allow. Form upload mechanisms, including that of uploading files through HTML forms, use the POST mechanism.

Definition at line 50 of file useragent.cpp.

References QNetworkAccessManager::put().

◆ putJson()

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().

◆ putJsonArray()

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().

◆ putJsonObject()

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().

◆ sendCustomRequest() [1/3]

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().

◆ sendCustomRequest() [2/3]

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().

◆ sendCustomRequest() [3/3]

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.

Note
This feature is currently available for HTTP(S) only.

Definition at line 66 of file useragent.cpp.

References QNetworkAccessManager::sendCustomRequest().

Referenced by sendCustomRequestJson(), sendCustomRequestJsonArray(), and sendCustomRequestJsonObject().

◆ sendCustomRequestJson()

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().

◆ sendCustomRequestJsonArray()

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().

◆ sendCustomRequestJsonObject()

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().