QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
|
A thread safe class for performing blocking (sync) network requests, with full support for QGIS proxy and authentication settings. More...
#include <qgsblockingnetworkrequest.h>
Public Types | |
enum | ErrorCode { NoError , NetworkError , TimeoutError , ServerExceptionError } |
Error codes. More... | |
enum class | RequestFlag : int { EmptyResponseIsValid = 1 << 0 } |
Request flags. More... | |
typedef QFlags< RequestFlag > | RequestFlags |
Public Slots | |
void | abort () |
Aborts the network request immediately. | |
Signals | |
Q_DECL_DEPRECATED void | downloadFinished () |
Emitted once a request has finished downloading. | |
void | downloadProgress (qint64 bytesReceived, qint64 bytesTotal) |
Emitted when when data arrives during a request. | |
void | finished () |
Emitted once a request has finished. | |
void | uploadProgress (qint64 bytesReceived, qint64 bytesTotal) |
Emitted when when data are sent during a request. | |
Public Member Functions | |
QgsBlockingNetworkRequest () | |
Constructor for QgsBlockingNetworkRequest. | |
~QgsBlockingNetworkRequest () override | |
QString | authCfg () const |
Returns the authentication config id which will be used during the request. | |
ErrorCode | deleteResource (QNetworkRequest &request, QgsFeedback *feedback=nullptr) |
Performs a "delete" operation on the specified request. | |
QString | errorMessage () const |
Returns the error message string, after a get(), post(), head() or put() request has been made. | |
ErrorCode | get (QNetworkRequest &request, bool forceRefresh=false, QgsFeedback *feedback=nullptr, RequestFlags requestFlags=QgsBlockingNetworkRequest::RequestFlags()) |
Performs a "get" operation on the specified request. | |
ErrorCode | head (QNetworkRequest &request, bool forceRefresh=false, QgsFeedback *feedback=nullptr) |
Performs a "head" operation on the specified request. | |
ErrorCode | post (QNetworkRequest &request, const QByteArray &data, bool forceRefresh=false, QgsFeedback *feedback=nullptr) |
This is an overloaded function. | |
ErrorCode | post (QNetworkRequest &request, QIODevice *data, bool forceRefresh=false, QgsFeedback *feedback=nullptr) |
Performs a "post" operation on the specified request, using the given data. | |
ErrorCode | put (QNetworkRequest &request, const QByteArray &data, QgsFeedback *feedback=nullptr) |
This is an overloaded function. | |
ErrorCode | put (QNetworkRequest &request, QIODevice *data, QgsFeedback *feedback=nullptr) |
Performs a "put" operation on the specified request, using the given data. | |
QgsNetworkReplyContent | reply () const |
Returns the content of the network reply, after a get(), post(), head() or put() request has been made. | |
void | setAuthCfg (const QString &authCfg) |
Sets the authentication config id which should be used during the request. | |
A thread safe class for performing blocking (sync) network requests, with full support for QGIS proxy and authentication settings.
This class should be used whenever a blocking network request is required. Unlike implementations which rely on QApplication::processEvents() or creation of a QEventLoop, this class is completely thread safe and can be used on either the main thread or background threads without issue.
Redirects are automatically handled by the class.
After completion of a request, the reply content should be retrieved by calling getReplyContent(). This method returns a QgsNetworkReplyContent container, which is safe and cheap to copy and pass between threads without issue.
Definition at line 46 of file qgsblockingnetworkrequest.h.
typedef QFlags< RequestFlag > QgsBlockingNetworkRequest::RequestFlags |
Definition at line 70 of file qgsblockingnetworkrequest.h.
Error codes.
Definition at line 52 of file qgsblockingnetworkrequest.h.
|
strong |
Request flags.
Enumerator | |
---|---|
EmptyResponseIsValid | Do not generate an error if getting an empty response (e.g. HTTP 204) |
Definition at line 65 of file qgsblockingnetworkrequest.h.
|
explicit |
Constructor for QgsBlockingNetworkRequest.
Definition at line 34 of file qgsblockingnetworkrequest.cpp.
|
override |
Definition at line 39 of file qgsblockingnetworkrequest.cpp.
|
slot |
Aborts the network request immediately.
Definition at line 285 of file qgsblockingnetworkrequest.cpp.
QString QgsBlockingNetworkRequest::authCfg | ( | ) | const |
Returns the authentication config id which will be used during the request.
Definition at line 50 of file qgsblockingnetworkrequest.cpp.
QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::deleteResource | ( | QNetworkRequest & | request, |
QgsFeedback * | feedback = nullptr |
||
) |
Performs a "delete" operation on the specified request.
If an authCfg() has been set, then any authentication configuration required will automatically be applied to request. There is no need to manually apply the authentication to the request prior to calling this method.
The optional feedback argument can be used to abort ongoing requests.
The method will return NoError if the get operation was successful. The contents of the reply can be retrieved by calling reply().
If an error was encountered then a specific ErrorCode will be returned, and a detailed error message can be retrieved by calling errorMessage().
Definition at line 98 of file qgsblockingnetworkrequest.cpp.
|
signal |
Emitted once a request has finished downloading.
|
signal |
Emitted when when data arrives during a request.
|
inline |
|
signal |
Emitted once a request has finished.
QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::get | ( | QNetworkRequest & | request, |
bool | forceRefresh = false , |
||
QgsFeedback * | feedback = nullptr , |
||
RequestFlags | requestFlags = QgsBlockingNetworkRequest::RequestFlags() |
||
) |
Performs a "get" operation on the specified request.
If forceRefresh is false
then previously cached replies may be used for the request. If it is set to true
then a new query is always performed.
If an authCfg() has been set, then any authentication configuration required will automatically be applied to request. There is no need to manually apply the authentication to the request prior to calling this method.
The optional feedback argument can be used to abort ongoing requests.
The optional requestFlags argument can be used to modify the behavior (added in QGIS 3.40).
The method will return NoError if the get operation was successful. The contents of the reply can be retrieved by calling reply().
If an error was encountered then a specific ErrorCode will be returned, and a detailed error message can be retrieved by calling errorMessage().
Definition at line 60 of file qgsblockingnetworkrequest.cpp.
QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::head | ( | QNetworkRequest & | request, |
bool | forceRefresh = false , |
||
QgsFeedback * | feedback = nullptr |
||
) |
Performs a "head" operation on the specified request.
If forceRefresh is false
then previously cached replies may be used for the request. If it is set to true
then a new query is always performed.
If an authCfg() has been set, then any authentication configuration required will automatically be applied to request. There is no need to manually apply the authentication to the request prior to calling this method.
The optional feedback argument can be used to abort ongoing requests.
The method will return NoError if the get operation was successful. The contents of the reply can be retrieved by calling reply().
If an error was encountered then a specific ErrorCode will be returned, and a detailed error message can be retrieved by calling errorMessage().
Definition at line 79 of file qgsblockingnetworkrequest.cpp.
QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::post | ( | QNetworkRequest & | request, |
const QByteArray & | data, | ||
bool | forceRefresh = false , |
||
QgsFeedback * | feedback = nullptr |
||
) |
This is an overloaded function.
Performs a "post" operation on the specified request, using the given data.
Definition at line 65 of file qgsblockingnetworkrequest.cpp.
QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::post | ( | QNetworkRequest & | request, |
QIODevice * | data, | ||
bool | forceRefresh = false , |
||
QgsFeedback * | feedback = nullptr |
||
) |
Performs a "post" operation on the specified request, using the given data.
If forceRefresh is false
then previously cached replies may be used for the request. If it is set to true
then a new query is always performed.
If an authCfg() has been set, then any authentication configuration required will automatically be applied to request. There is no need to manually apply the authentication to the request prior to calling this method.
The optional feedback argument can be used to abort ongoing requests.
The method will return NoError if the get operation was successful. The contents of the reply can be retrieved by calling reply().
If an error was encountered then a specific ErrorCode will be returned, and a detailed error message can be retrieved by calling errorMessage().
Definition at line 73 of file qgsblockingnetworkrequest.cpp.
QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::put | ( | QNetworkRequest & | request, |
const QByteArray & | data, | ||
QgsFeedback * | feedback = nullptr |
||
) |
This is an overloaded function.
Performs a "put" operation on the specified request, using the given data.
Definition at line 84 of file qgsblockingnetworkrequest.cpp.
QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::put | ( | QNetworkRequest & | request, |
QIODevice * | data, | ||
QgsFeedback * | feedback = nullptr |
||
) |
Performs a "put" operation on the specified request, using the given data.
If an authCfg() has been set, then any authentication configuration required will automatically be applied to request. There is no need to manually apply the authentication to the request prior to calling this method.
The optional feedback argument can be used to abort ongoing requests.
The method will return NoError if the get operation was successful. The contents of the reply can be retrieved by calling reply().
If an error was encountered then a specific ErrorCode will be returned, and a detailed error message can be retrieved by calling errorMessage().
Definition at line 92 of file qgsblockingnetworkrequest.cpp.
|
inline |
void QgsBlockingNetworkRequest::setAuthCfg | ( | const QString & | authCfg | ) |
Sets the authentication config id which should be used during the request.
Definition at line 55 of file qgsblockingnetworkrequest.cpp.
|
signal |
Emitted when when data are sent during a request.