18 #ifndef QGSNETWORKACCESSMANAGER_H 19 #define QGSNETWORKACCESSMANAGER_H 24 #include <QStringList> 25 #include <QNetworkAccessManager> 26 #include <QNetworkProxy> 27 #include <QNetworkRequest> 29 #include <QWaitCondition> 32 #include "qgis_core.h" 38 #include "qgsconfig.h" 39 constexpr
int sFilePrefixLength = CMAKE_SOURCE_DIR[
sizeof( CMAKE_SOURCE_DIR ) - 1] ==
'/' ?
sizeof( CMAKE_SOURCE_DIR ) + 1 :
sizeof( CMAKE_SOURCE_DIR );
41 #define QgsSetRequestInitiatorClass(request, _class) request.setAttribute( static_cast< QNetworkRequest::Attribute >( QgsNetworkRequestParameters::AttributeInitiatorClass ), _class ); request.setAttribute( static_cast< QNetworkRequest::Attribute >( QgsNetworkRequestParameters::AttributeInitiatorRequestId ), QString( __FILE__ ).mid( sFilePrefixLength ) + ':' + QString::number( __LINE__ ) + " (" + __FUNCTION__ + ")" ); 42 #define QgsSetRequestInitiatorId(request, str) request.setAttribute( static_cast< QNetworkRequest::Attribute >( QgsNetworkRequestParameters::AttributeInitiatorRequestId ), QString( __FILE__ ).mid( sFilePrefixLength ) + ':' + QString::number( __LINE__ ) + " (" + __FUNCTION__ + "): " + str ); 58 AttributeInitiatorClass = QNetworkRequest::User + 3000,
72 const QNetworkRequest &request,
74 const QByteArray &content = QByteArray() );
79 QNetworkAccessManager::Operation
operation()
const {
return mOperation; }
87 QNetworkRequest
request()
const {
return mRequest; }
103 QByteArray
content()
const {
return mContent; }
128 QNetworkAccessManager::Operation mOperation;
129 QNetworkRequest mRequest;
130 QString mOriginatingThreadId;
133 QString mInitiatorClass;
134 QVariant mInitiatorRequestId;
186 virtual void handleSslErrors( QNetworkReply *reply,
const QList<QSslError> &errors );
228 virtual void handleAuthRequest( QNetworkReply *reply, QAuthenticator *auth );
297 void setSslErrorHandler( std::unique_ptr< QgsSslErrorHandler > handler );
315 void setAuthHandler( std::unique_ptr< QgsNetworkAuthenticationHandler > handler );
326 void insertProxyFactory( QNetworkProxyFactory *factory
SIP_TRANSFER );
342 const QList<QNetworkProxyFactory *> proxyFactories()
const;
352 const QNetworkProxy &fallbackProxy()
const;
362 QStringList excludeList()
const;
373 void setFallbackProxyAndExcludes(
const QNetworkProxy &proxy,
const QStringList &excludes );
380 static QString cacheLoadControlName( QNetworkRequest::CacheLoadControl control );
387 static QNetworkRequest::CacheLoadControl cacheLoadControlFromName(
const QString &name );
396 void setupDefaultProxyAndCache( Qt::ConnectionType connectionType = Qt::BlockingQueuedConnection );
409 static int timeout();
417 static void setTimeout(
int time );
439 static QgsNetworkReplyContent blockingGet( QNetworkRequest &request,
const QString &authCfg = QString(),
bool forceRefresh =
false,
QgsFeedback *feedback =
nullptr );
461 static QgsNetworkReplyContent blockingPost( QNetworkRequest &request,
const QByteArray &data,
const QString &authCfg = QString(),
bool forceRefresh =
false,
QgsFeedback *feedback =
nullptr );
468 Q_DECL_DEPRECATED
void requestAboutToBeCreated( QNetworkAccessManager::Operation,
const QNetworkRequest &, QIODevice * )
SIP_DEPRECATED;
526 void downloadProgress(
int requestId, qint64 bytesReceived, qint64 bytesTotal );
543 void requestRequiresAuth(
int requestId,
const QString &realm );
560 void requestAuthDetailsAdded(
int requestId,
const QString &realm,
const QString &user,
const QString &password );
578 void requestEncounteredSslErrors(
int requestId,
const QList<QSslError> &errors );
583 void sslErrorsOccurred( QNetworkReply *,
const QList<QSslError> &errors );
584 void sslErrorsHandled( QNetworkReply *reply );
593 Q_DECL_DEPRECATED
void requestCreated( QNetworkReply * )
SIP_DEPRECATED;
595 void requestTimedOut( QNetworkReply * );
600 void authRequestOccurred( QNetworkReply *, QAuthenticator *auth );
601 void authRequestHandled( QNetworkReply *reply );
609 void onReplyFinished( QNetworkReply *reply );
611 void onReplyDownloadProgress( qint64 bytesReceived, qint64 bytesTotal );
613 void onReplySslErrors(
const QList<QSslError> &errors );
615 void handleSslErrors( QNetworkReply *reply,
const QList<QSslError> &errors );
618 void onAuthRequired( QNetworkReply *reply, QAuthenticator *auth );
619 void handleAuthRequest( QNetworkReply *reply, QAuthenticator *auth );
622 QNetworkReply *createRequest( QNetworkAccessManager::Operation op,
const QNetworkRequest &req, QIODevice *outgoingData =
nullptr )
override;
626 void unlockAfterSslErrorHandled();
627 void afterSslErrorHandled( QNetworkReply *reply );
630 void unlockAfterAuthRequestHandled();
631 void afterAuthRequestHandled( QNetworkReply *reply );
633 void pauseTimeout( QNetworkReply *reply );
634 void restartTimeout( QNetworkReply *reply );
635 static int getRequestId( QNetworkReply *reply );
637 QList<QNetworkProxyFactory *> mProxyFactories;
638 QNetworkProxy mFallbackProxy;
639 QStringList mExcludedURLs;
640 bool mUseSystemProxy =
false;
641 bool mInitialized =
false;
644 std::unique_ptr< QgsSslErrorHandler > mSslErrorHandler;
646 QMutex mSslErrorHandlerMutex;
648 QWaitCondition mSslErrorWaitCondition;
651 std::unique_ptr< QgsNetworkAuthenticationHandler > mAuthHandler;
653 QMutex mAuthRequestHandlerMutex;
655 QWaitCondition mAuthRequestWaitCondition;
659 #endif // QGSNETWORKACCESSMANAGER_H QVariant initiatorRequestId() const
Returns the internal ID used by the object which initiated this request to identify individual reques...
QByteArray content() const
Returns the request's content.
constexpr int sFilePrefixLength
Encapsulates parameters and properties of a network request.
int requestId() const
Returns a unique ID identifying the request.
Base class for feedback objects to be used for cancelation of something running in a worker thread...
Internal ID used by originator object to identify requests.
SSL error handler, used for responding to SSL errors encountered during network requests.
QString initiatorClassName() const
Returns the class name of the object which initiated this request.
QNetworkRequest request() const
Returns the network request.
QNetworkAccessManager::Operation operation() const
Returns the request operation, e.g.
Network authentication handler, used for responding to network authentication requests during network...
Encapsulates a network reply within a container which is inexpensive to copy and safe to pass between...
QString originatingThreadId() const
Returns a string identifying the thread which the request originated from.
bool useSystemProxy() const
Returns whether the system proxy should be used.
RequestAttributes
Custom request attributes.
network access manager for QGISThis class implements the QGIS network access manager.