QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
network access manager for QGIS More...
#include <qgsnetworkaccessmanager.h>
Signals | |
void | downloadProgress (int requestId, qint64 bytesReceived, qint64 bytesTotal) |
Emitted when a network reply receives a progress report. More... | |
void | finished (QgsNetworkReplyContent reply) |
Emitted whenever a pending network reply is finished. More... | |
void | requestAboutToBeCreated (QgsNetworkRequestParameters request) |
Emitted when a network request is about to be created. More... | |
Q_DECL_DEPRECATED void | requestAboutToBeCreated (QNetworkAccessManager::Operation, const QNetworkRequest &, QIODevice *) |
void | requestAuthDetailsAdded (int requestId, const QString &realm, const QString &user, const QString &password) |
Emitted when network authentication details have been added to a request. More... | |
Q_DECL_DEPRECATED void | requestCreated (QNetworkReply *) |
void | requestEncounteredSslErrors (int requestId, const QList< QSslError > &errors) |
Emitted when a network request encounters SSL errors. More... | |
void | requestRequiresAuth (int requestId, const QString &realm) |
Emitted when a network request prompts an authentication request. More... | |
void | requestTimedOut (QgsNetworkRequestParameters request) |
Emitted when a network request has timed out. More... | |
void | requestTimedOut (QNetworkReply *) |
Public Member Functions | |
QgsNetworkAccessManager (QObject *parent=nullptr) | |
QStringList | excludeList () const |
Returns the proxy exclude list. More... | |
const QNetworkProxy & | fallbackProxy () const |
Returns the fallback proxy used by the manager. More... | |
void | insertProxyFactory (QNetworkProxyFactory *factory) |
Inserts a factory into the proxy factories list. More... | |
QStringList | noProxyList () const |
Returns the no proxy list. More... | |
const QList< QNetworkProxyFactory * > | proxyFactories () const |
Returns a list of proxy factories used by the manager. More... | |
void | removeProxyFactory (QNetworkProxyFactory *factory) |
Removes a factory from the proxy factories list. More... | |
void | setAuthHandler (std::unique_ptr< QgsNetworkAuthenticationHandler > handler) |
Sets the application network authentication handler, which is used to respond to network authentication prompts during network requests. More... | |
void | setFallbackProxyAndExcludes (const QNetworkProxy &proxy, const QStringList &excludes, const QStringList &noProxyURLs) |
Sets the fallback proxy and URLs which shouldn't use it. More... | |
void | setSslErrorHandler (std::unique_ptr< QgsSslErrorHandler > handler) |
Sets the application SSL error handler, which is used to respond to SSL errors encountered during network requests. More... | |
void | setupDefaultProxyAndCache (Qt::ConnectionType connectionType=Qt::BlockingQueuedConnection) |
Setup the QgsNetworkAccessManager (NAM) according to the user's settings. More... | |
bool | useSystemProxy () const |
Returns whether the system proxy should be used. More... | |
Static Public Member Functions | |
static QgsNetworkReplyContent | blockingGet (QNetworkRequest &request, const QString &authCfg=QString(), bool forceRefresh=false, QgsFeedback *feedback=nullptr) |
Posts a GET request to obtain the contents of the target request and returns a new QgsNetworkReplyContent object for reading. More... | |
static QgsNetworkReplyContent | blockingPost (QNetworkRequest &request, const QByteArray &data, const QString &authCfg=QString(), bool forceRefresh=false, QgsFeedback *feedback=nullptr) |
Posts a POST request to obtain the contents of the target request, using the given data, and returns a new QgsNetworkReplyContent object for reading. More... | |
static QNetworkRequest::CacheLoadControl | cacheLoadControlFromName (const QString &name) |
Returns QNetworkRequest::CacheLoadControl from a name. More... | |
static QString | cacheLoadControlName (QNetworkRequest::CacheLoadControl control) |
Returns the name for QNetworkRequest::CacheLoadControl. More... | |
static QgsNetworkAccessManager * | instance (Qt::ConnectionType connectionType=Qt::BlockingQueuedConnection) |
Returns a pointer to the active QgsNetworkAccessManager for the current thread. More... | |
static void | setTimeout (int time) |
Sets the maximum timeout time for network requests, in milliseconds. More... | |
static int | timeout () |
Returns the network timeout length, in milliseconds. More... | |
Protected Member Functions | |
QNetworkReply * | createRequest (QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *outgoingData=nullptr) override |
network access manager for QGIS
This class implements the QGIS network access manager. It's a singleton that can be used across QGIS.
Plugins can insert proxy factories and thereby redirect requests to individual proxies.
If no proxy factories are there or none returns a proxy for an URL a fallback proxy can be set. There's also a exclude list that defines URLs that the fallback proxy should not be used for, then no proxy will be used.
Definition at line 251 of file qgsnetworkaccessmanager.h.
QgsNetworkAccessManager::QgsNetworkAccessManager | ( | QObject * | parent = nullptr | ) |
Definition at line 135 of file qgsnetworkaccessmanager.cpp.
|
static |
Posts a GET request to obtain the contents of the target request and returns a new QgsNetworkReplyContent object for reading.
The current thread will be blocked until the request is returned.
This method is safe to call in either the main thread or a worker thread.
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 specified, then that 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 contents of the reply will be returned after the request is completed or an error occurs.
Definition at line 652 of file qgsnetworkaccessmanager.cpp.
|
static |
Posts a POST request to obtain the contents of the target request, using the given data, and returns a new QgsNetworkReplyContent object for reading.
The current thread will be blocked until the request is returned.
This method is safe to call in either the main thread or a worker thread.
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 specified, then that 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 contents of the reply will be returned after the request is completed or an error occurs.
Definition at line 660 of file qgsnetworkaccessmanager.cpp.
|
static |
Returns QNetworkRequest::CacheLoadControl from a name.
Definition at line 478 of file qgsnetworkaccessmanager.cpp.
|
static |
Returns the name for QNetworkRequest::CacheLoadControl.
Definition at line 462 of file qgsnetworkaccessmanager.cpp.
|
overrideprotected |
Definition at line 215 of file qgsnetworkaccessmanager.cpp.
|
signal |
Emitted when a network reply receives a progress report.
The requestId argument reflects the unique ID identifying the original request which the progress report relates to.
The bytesReceived parameter indicates the number of bytes received, while bytesTotal indicates the total number of bytes expected to be downloaded. If the number of bytes to be downloaded is not known, bytesTotal will be -1.
This signal is propagated to the main thread QgsNetworkAccessManager instance, so it is necessary only to connect to the main thread's signal in order to receive notifications about requests created in any thread.
QStringList QgsNetworkAccessManager::excludeList | ( | ) | const |
Returns the proxy exclude list.
This list consists of the beginning of URL strings which will not use the fallback proxy.
Definition at line 168 of file qgsnetworkaccessmanager.cpp.
const QNetworkProxy & QgsNetworkAccessManager::fallbackProxy | ( | ) | const |
Returns the fallback proxy used by the manager.
The fallback proxy is used for URLs which no other proxy factory returned proxies for.
Definition at line 178 of file qgsnetworkaccessmanager.cpp.
|
signal |
Emitted whenever a pending network reply is finished.
The reply parameter will contain a QgsNetworkReplyContent object, containing all the useful information relating to the reply, including headers and reply content.
This signal is propagated to the main thread QgsNetworkAccessManager instance, so it is necessary only to connect to the main thread's signal in order to receive notifications about requests created in any thread.
void QgsNetworkAccessManager::insertProxyFactory | ( | QNetworkProxyFactory * | factory | ) |
Inserts a factory into the proxy factories list.
Ownership of factory is transferred to the manager.
Definition at line 153 of file qgsnetworkaccessmanager.cpp.
|
static |
Returns a pointer to the active QgsNetworkAccessManager for the current thread.
With the connectionType parameter it is possible to setup the default connection type that is used to handle signals that might require user interaction and therefore need to be handled on the main thread. See in-depth discussion below.
connectionType | In most cases the default of using a Qt::BlockingQueuedConnection is ok, to make a background thread wait for the main thread to answer such a request is fine and anything else is dangerous. However, in case the request was started on the main thread, one should execute a local event loop in a helper thread and freeze the main thread for the duration of the download. In this case, if an authentication request is sent from the background thread network access manager, the background thread should be blocked, the main thread be woken up, processEvents() executed once, the main thread frozen again and the background thread continued. |
Definition at line 121 of file qgsnetworkaccessmanager.cpp.
QStringList QgsNetworkAccessManager::noProxyList | ( | ) | const |
Returns the no proxy list.
This list consists of the beginning of URL strings which will not use any proxy at all
Definition at line 173 of file qgsnetworkaccessmanager.cpp.
const QList< QNetworkProxyFactory * > QgsNetworkAccessManager::proxyFactories | ( | ) | const |
Returns a list of proxy factories used by the manager.
Definition at line 163 of file qgsnetworkaccessmanager.cpp.
void QgsNetworkAccessManager::removeProxyFactory | ( | QNetworkProxyFactory * | factory | ) |
Removes a factory from the proxy factories list.
Definition at line 158 of file qgsnetworkaccessmanager.cpp.
|
signal |
Emitted when a network request is about to be created.
This signal is propagated to the main thread QgsNetworkAccessManager instance, so it is necessary only to connect to the main thread's signal in order to receive notifications about requests created in any thread.
|
signal |
|
signal |
Emitted when network authentication details have been added to a request.
The requestId argument reflects the unique ID identifying the original request which the authentication relates to.
This signal is always sent from the main thread QgsNetworkAccessManager instance, so it is necessary only to connect to the main thread's signal in order to receive notifications about authentication requests from any thread.
This signal is for debugging and logging purposes only, and should not be used to respond to the requests. See QgsNetworkAuthenticationHandler for details on how to handle authentication requests.
|
signal |
|
signal |
Emitted when a network request encounters SSL errors.
The requestId argument reflects the unique ID identifying the original request which the SSL error relates to.
This signal is propagated to the main thread QgsNetworkAccessManager instance, so it is necessary only to connect to the main thread's signal in order to receive notifications about SSL errors from any thread.
This signal is for debugging and logging purposes only, and cannot be used to respond to the errors. See QgsSslErrorHandler for details on how to handle SSL errors and potentially ignore them.
|
signal |
Emitted when a network request prompts an authentication request.
The requestId argument reflects the unique ID identifying the original request which the authentication relates to.
This signal is propagated to the main thread QgsNetworkAccessManager instance, so it is necessary only to connect to the main thread's signal in order to receive notifications about authentication requests from any thread.
This signal is for debugging and logging purposes only, and cannot be used to respond to the requests. See QgsNetworkAuthenticationHandler for details on how to handle authentication requests.
|
signal |
Emitted when a network request has timed out.
This signal is propagated to the main thread QgsNetworkAccessManager instance, so it is necessary only to connect to the main thread's signal in order to receive notifications about requests created in any thread.
|
signal |
void QgsNetworkAccessManager::setAuthHandler | ( | std::unique_ptr< QgsNetworkAuthenticationHandler > | handler | ) |
Sets the application network authentication handler, which is used to respond to network authentication prompts during network requests.
Ownership of handler is transferred to the main thread QgsNetworkAccessManager instance.
This method must ONLY be called on the main thread QgsNetworkAccessManager. It is not necessary to set handlers for background threads – the main thread QgsNetworkAuthenticationHandler will automatically be used in a thread-safe manner for any authentication requests encountered on background threads.
The default QgsNetworkAuthenticationHandler responds to request only by logging the request, but does not provide any username or password resolution.
Definition at line 147 of file qgsnetworkaccessmanager.cpp.
void QgsNetworkAccessManager::setFallbackProxyAndExcludes | ( | const QNetworkProxy & | proxy, |
const QStringList & | excludes, | ||
const QStringList & | noProxyURLs | ||
) |
Sets the fallback proxy and URLs which shouldn't use it.
The fallback proxy is used for URLs which no other proxy factory returned proxies for. The excludes list specifies the beginning of URL strings which will not use this fallback proxy. The noProxyURLs list specifies the beginning of URL strings which will not use any proxy at all
Definition at line 183 of file qgsnetworkaccessmanager.cpp.
void QgsNetworkAccessManager::setSslErrorHandler | ( | std::unique_ptr< QgsSslErrorHandler > | handler | ) |
Sets the application SSL error handler, which is used to respond to SSL errors encountered during network requests.
Ownership of handler is transferred to the main thread QgsNetworkAccessManager instance.
This method must ONLY be called on the main thread QgsNetworkAccessManager. It is not necessary to set handlers for background threads – the main thread QgsSslErrorHandler will automatically be used in a thread-safe manner for any SSL errors encountered on background threads.
The default QgsSslErrorHandler responds to SSL errors only by logging the errors, and uses the default Qt response, which is to abort the request.
Definition at line 141 of file qgsnetworkaccessmanager.cpp.
|
static |
Sets the maximum timeout time for network requests, in milliseconds.
Definition at line 647 of file qgsnetworkaccessmanager.cpp.
void QgsNetworkAccessManager::setupDefaultProxyAndCache | ( | Qt::ConnectionType | connectionType = Qt::BlockingQueuedConnection | ) |
Setup the QgsNetworkAccessManager (NAM) according to the user's settings.
The connectionType sets up the default connection type that is used to handle signals that might require user interaction and therefore need to be handled on the main thread. See in-depth discussion in the documentation for the constructor of this class.
Definition at line 499 of file qgsnetworkaccessmanager.cpp.
|
static |
Returns the network timeout length, in milliseconds.
Definition at line 642 of file qgsnetworkaccessmanager.cpp.
|
inline |
Returns whether the system proxy should be used.
Definition at line 415 of file qgsnetworkaccessmanager.h.