37 #include <QNetworkReply>
38 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
41 #include <QRecursiveMutex>
43 #include <QThreadStorage>
44 #include <QAuthenticator>
45 #include <QStandardPaths>
49 #include <QSslConfiguration>
57 static std::vector< std::pair< QString, std::function< void( QNetworkRequest * ) > > > sCustomPreprocessors;
60 class QgsNetworkProxyFactory :
public QNetworkProxyFactory
63 QgsNetworkProxyFactory() =
default;
65 QList<QNetworkProxy> queryProxy(
const QNetworkProxyQuery &query = QNetworkProxyQuery() )
override
71 for ( QNetworkProxyFactory *f : constProxyFactories )
73 QList<QNetworkProxy> systemproxies = QNetworkProxyFactory::systemProxyForQuery( query );
74 if ( !systemproxies.isEmpty() )
77 QList<QNetworkProxy> proxies = f->queryProxy( query );
78 if ( !proxies.isEmpty() )
83 if ( query.queryType() != QNetworkProxyQuery::UrlRequest )
86 const QString url = query.url().toString();
89 for (
const QString &noProxy : constNoProxyList )
91 if ( !noProxy.trimmed().isEmpty() && url.startsWith( noProxy ) )
93 QgsDebugMsgLevel( QStringLiteral(
"don't using any proxy for %1 [exclude %2]" ).arg( url, noProxy ), 4 );
94 return QList<QNetworkProxy>() << QNetworkProxy( QNetworkProxy::NoProxy );
99 for (
const QString &exclude : constExcludeList )
101 if ( !exclude.trimmed().isEmpty() && url.startsWith( exclude ) )
103 QgsDebugMsgLevel( QStringLiteral(
"using default proxy for %1 [exclude %2]" ).arg( url, exclude ), 4 );
104 return QList<QNetworkProxy>() << QNetworkProxy( QNetworkProxy::DefaultProxy );
110 QgsDebugMsgLevel( QStringLiteral(
"requesting system proxy for query %1" ).arg( url ), 4 );
111 QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery( query );
112 if ( !proxies.isEmpty() )
115 .arg( proxies.first().hostName() ).arg( proxies.first().port() ), 4 );
120 QgsDebugMsgLevel( QStringLiteral(
"using fallback proxy for %1" ).arg( url ), 4 );
127 class QgsNetworkCookieJar :
public QNetworkCookieJar
133 : QNetworkCookieJar( parent )
135 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
136 , mMutex( QMutex::Recursive )
140 bool deleteCookie(
const QNetworkCookie &cookie )
override
142 const QMutexLocker locker( &mMutex );
143 if ( QNetworkCookieJar::deleteCookie( cookie ) )
145 emit mNam->cookiesChanged( allCookies() );
150 bool insertCookie(
const QNetworkCookie &cookie )
override
152 const QMutexLocker locker( &mMutex );
153 if ( QNetworkCookieJar::insertCookie( cookie ) )
155 emit mNam->cookiesChanged( allCookies() );
160 bool setCookiesFromUrl(
const QList<QNetworkCookie> &cookieList,
const QUrl &url )
override
162 const QMutexLocker locker( &mMutex );
163 return QNetworkCookieJar::setCookiesFromUrl( cookieList, url );
165 bool updateCookie(
const QNetworkCookie &cookie )
override
167 const QMutexLocker locker( &mMutex );
168 if ( QNetworkCookieJar::updateCookie( cookie ) )
170 emit mNam->cookiesChanged( allCookies() );
177 QList<QNetworkCookie> allCookies()
const
179 const QMutexLocker locker( &mMutex );
180 return QNetworkCookieJar::allCookies();
182 void setAllCookies(
const QList<QNetworkCookie> &cookieList )
184 const QMutexLocker locker( &mMutex );
185 QNetworkCookieJar::setAllCookies( cookieList );
189 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
190 mutable QMutex mMutex;
192 mutable QRecursiveMutex mMutex;
203 static QThreadStorage<QgsNetworkAccessManager> sInstances;
206 if ( nam->thread() == qApp->thread() )
209 if ( !nam->mInitialized )
219 : QNetworkAccessManager( parent )
220 , mAuthRequestHandlerSemaphore( 1 )
222 setProxyFactory(
new QgsNetworkProxyFactory() );
223 setCookieJar(
new QgsNetworkCookieJar(
this ) );
228 Q_ASSERT( sMainNAM ==
this );
229 mSslErrorHandler = std::move( handler );
234 Q_ASSERT( sMainNAM ==
this );
235 mAuthHandler = std::move( handler );
240 mProxyFactories.insert( 0, factory );
245 mProxyFactories.removeAll( factory );
250 return mProxyFactories;
255 return mExcludedURLs;
265 return mFallbackProxy;
270 QgsDebugMsgLevel( QStringLiteral(
"proxy settings: (type:%1 host: %2:%3, user:%4, password:%5" )
271 .arg( proxy.type() == QNetworkProxy::DefaultProxy ? QStringLiteral(
"DefaultProxy" ) :
272 proxy.type() == QNetworkProxy::Socks5Proxy ? QStringLiteral(
"Socks5Proxy" ) :
273 proxy.type() == QNetworkProxy::NoProxy ? QStringLiteral(
"NoProxy" ) :
274 proxy.type() == QNetworkProxy::HttpProxy ? QStringLiteral(
"HttpProxy" ) :
275 proxy.type() == QNetworkProxy::HttpCachingProxy ? QStringLiteral(
"HttpCachingProxy" ) :
276 proxy.type() == QNetworkProxy::FtpCachingProxy ? QStringLiteral(
"FtpCachingProxy" ) :
277 QStringLiteral(
"Undefined" ),
281 proxy.password().isEmpty() ? QStringLiteral(
"not set" ) : QStringLiteral(
"set" ) ), 4 );
283 mFallbackProxy = proxy;
284 mExcludedURLs = excludes;
286 mExcludedURLs.erase( std::remove_if( mExcludedURLs.begin(), mExcludedURLs.end(),
287 [](
const QString & url )
289 return url.trimmed().isEmpty();
290 } ), mExcludedURLs.end() );
292 mNoProxyURLs = noProxyURLs;
293 mNoProxyURLs.erase( std::remove_if( mNoProxyURLs.begin(), mNoProxyURLs.end(),
294 [](
const QString & url )
296 return url.trimmed().isEmpty();
297 } ), mNoProxyURLs.end() );
304 QNetworkRequest *pReq(
const_cast< QNetworkRequest *
>( &req ) );
306 QString userAgent = s.
value( QStringLiteral(
"/qgis/networkAndProxy/userAgent" ),
"Mozilla/5.0" ).toString();
307 if ( !userAgent.isEmpty() )
309 userAgent += QStringLiteral(
"QGIS/%1/%2" ).arg(
Qgis::versionInt() ).arg( QSysInfo::prettyProductName() );
310 pReq->setRawHeader(
"User-Agent", userAgent.toLatin1() );
313 const bool ishttps = pReq->url().scheme().compare( QLatin1String(
"https" ), Qt::CaseInsensitive ) == 0;
316 QgsDebugMsgLevel( QStringLiteral(
"Adding trusted CA certs to request" ), 3 );
317 QSslConfiguration sslconfig( pReq->sslConfiguration() );
321 const QString hostport( QStringLiteral(
"%1:%2" )
322 .arg( pReq->url().host().trimmed() )
323 .arg( pReq->url().port() != -1 ? pReq->url().port() : 443 ) );
325 if ( !servconfig.
isNull() )
327 QgsDebugMsg( QStringLiteral(
"Adding SSL custom config to request for %1" ).arg( hostport ) );
333 pReq->setSslConfiguration( sslconfig );
337 if ( sMainNAM->mCacheDisabled )
340 pReq->setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork );
341 pReq->setAttribute( QNetworkRequest::CacheSaveControlAttribute,
false );
344 for (
const auto &preprocessor : sCustomPreprocessors )
346 preprocessor.second( pReq );
349 static QAtomicInt sRequestId = 0;
350 const int requestId = ++sRequestId;
352 if ( QBuffer *buffer = qobject_cast<QBuffer *>( outgoingData ) )
354 content = buffer->buffer();
361 QNetworkReply *reply = QNetworkAccessManager::createRequest( op, req, outgoingData );
362 reply->setProperty(
"requestId", requestId );
368 connect( reply, &QNetworkReply::downloadProgress,
this, &QgsNetworkAccessManager::onReplyDownloadProgress );
370 connect( reply, &QNetworkReply::sslErrors,
this, &QgsNetworkAccessManager::onReplySslErrors );
378 QTimer *timer =
new QTimer( reply );
379 timer->setObjectName( QStringLiteral(
"timeoutTimer" ) );
380 connect( timer, &QTimer::timeout,
this, &QgsNetworkAccessManager::abortRequest );
381 timer->setSingleShot(
true );
384 connect( reply, &QNetworkReply::downloadProgress, timer, [timer] { timer->start(); } );
385 connect( reply, &QNetworkReply::uploadProgress, timer, [timer] { timer->start(); } );
386 connect( reply, &QNetworkReply::finished, timer, &QTimer::stop );
388 QgsDebugMsgLevel( QStringLiteral(
"Created [reply:%1]" ).arg(
reinterpret_cast< qint64
>( reply ), 0, 16 ), 3 );
394 void QgsNetworkAccessManager::unlockAfterSslErrorHandled()
396 Q_ASSERT( QThread::currentThread() == QApplication::instance()->thread() );
397 mSslErrorWaitCondition.wakeOne();
401 void QgsNetworkAccessManager::abortRequest()
403 QTimer *timer = qobject_cast<QTimer *>( sender() );
406 QNetworkReply *reply = qobject_cast<QNetworkReply *>( timer->parent() );
410 QgsDebugMsgLevel( QStringLiteral(
"Abort [reply:%1] %2" ).arg(
reinterpret_cast< qint64
>( reply ), 0, 16 ).arg( reply->url().toString() ), 3 );
417 void QgsNetworkAccessManager::onReplyFinished( QNetworkReply *reply )
422 void QgsNetworkAccessManager::onReplyDownloadProgress( qint64 bytesReceived, qint64 bytesTotal )
424 if ( QNetworkReply *reply = qobject_cast< QNetworkReply *>( sender() ) )
431 void QgsNetworkAccessManager::onReplySslErrors(
const QList<QSslError> &errors )
433 QNetworkReply *reply = qobject_cast< QNetworkReply *>( sender() );
435 Q_ASSERT( reply->manager() ==
this );
437 QgsDebugMsg( QStringLiteral(
"Stopping network reply timeout whilst SSL error is handled" ) );
438 pauseTimeout( reply );
444 emit sslErrorsOccurred( reply, errors );
445 if (
this != sMainNAM )
449 mSslErrorHandlerMutex.lock();
450 mSslErrorWaitCondition.wait( &mSslErrorHandlerMutex );
451 mSslErrorHandlerMutex.unlock();
452 afterSslErrorHandled( reply );
456 void QgsNetworkAccessManager::afterSslErrorHandled( QNetworkReply *reply )
458 if ( reply->manager() ==
this )
460 restartTimeout( reply );
461 emit sslErrorsHandled( reply );
463 else if (
this == sMainNAM )
466 qobject_cast< QgsNetworkAccessManager *>( reply->manager() )->unlockAfterSslErrorHandled();
470 void QgsNetworkAccessManager::afterAuthRequestHandled( QNetworkReply *reply )
472 if ( reply->manager() ==
this )
474 restartTimeout( reply );
475 emit authRequestHandled( reply );
479 void QgsNetworkAccessManager::pauseTimeout( QNetworkReply *reply )
481 Q_ASSERT( reply->manager() ==
this );
483 QTimer *timer = reply->findChild<QTimer *>( QStringLiteral(
"timeoutTimer" ) );
484 if ( timer && timer->isActive() )
490 void QgsNetworkAccessManager::restartTimeout( QNetworkReply *reply )
492 Q_ASSERT( reply->manager() ==
this );
494 QTimer *timer = reply->findChild<QTimer *>( QStringLiteral(
"timeoutTimer" ) );
497 Q_ASSERT( !timer->isActive() );
498 QgsDebugMsg( QStringLiteral(
"Restarting network reply timeout" ) );
499 timer->setSingleShot(
true );
504 int QgsNetworkAccessManager::getRequestId( QNetworkReply *reply )
506 return reply->property(
"requestId" ).toInt();
509 void QgsNetworkAccessManager::handleSslErrors( QNetworkReply *reply,
const QList<QSslError> &errors )
511 mSslErrorHandler->handleSslErrors( reply, errors );
512 afterSslErrorHandled( reply );
517 void QgsNetworkAccessManager::onAuthRequired( QNetworkReply *reply, QAuthenticator *auth )
520 Q_ASSERT( reply->manager() ==
this );
522 QgsDebugMsg( QStringLiteral(
"Stopping network reply timeout whilst auth request is handled" ) );
523 pauseTimeout( reply );
527 mAuthRequestHandlerSemaphore.acquire();
530 emit authRequestOccurred( reply, auth );
532 if (
this != sMainNAM )
536 mAuthRequestHandlerSemaphore.acquire();
537 mAuthRequestHandlerSemaphore.release();
538 afterAuthRequestHandled( reply );
544 if (
this != sMainNAM )
550 mAuthHandler->handleAuthRequestOpenBrowser( url );
555 if (
this != sMainNAM )
561 mAuthHandler->handleAuthRequestCloseBrowser();
566 if (
this != sMainNAM )
573 void QgsNetworkAccessManager::handleAuthRequest( QNetworkReply *reply, QAuthenticator *auth )
575 mAuthHandler->handleAuthRequest( reply, auth );
579 afterAuthRequestHandled( reply );
580 qobject_cast<QgsNetworkAccessManager *>( reply->manager() )->mAuthRequestHandlerSemaphore.release();
587 case QNetworkRequest::AlwaysNetwork:
588 return QStringLiteral(
"AlwaysNetwork" );
589 case QNetworkRequest::PreferNetwork:
590 return QStringLiteral(
"PreferNetwork" );
591 case QNetworkRequest::PreferCache:
592 return QStringLiteral(
"PreferCache" );
593 case QNetworkRequest::AlwaysCache:
594 return QStringLiteral(
"AlwaysCache" );
596 return QStringLiteral(
"PreferNetwork" );
601 if ( name == QLatin1String(
"AlwaysNetwork" ) )
603 return QNetworkRequest::AlwaysNetwork;
605 else if ( name == QLatin1String(
"PreferNetwork" ) )
607 return QNetworkRequest::PreferNetwork;
609 else if ( name == QLatin1String(
"PreferCache" ) )
611 return QNetworkRequest::PreferCache;
613 else if ( name == QLatin1String(
"AlwaysCache" ) )
615 return QNetworkRequest::AlwaysCache;
617 return QNetworkRequest::PreferNetwork;
623 mUseSystemProxy =
false;
625 Q_ASSERT( sMainNAM );
627 if ( sMainNAM !=
this )
629 connect(
this, &QNetworkAccessManager::proxyAuthenticationRequired,
630 sMainNAM, &QNetworkAccessManager::proxyAuthenticationRequired,
648 connect(
this, &QNetworkAccessManager::sslErrors,
649 sMainNAM, &QNetworkAccessManager::sslErrors,
664 setAuthHandler( std::make_unique< QgsNetworkAuthenticationHandler>() );
667 connect(
this, &QgsNetworkAccessManager::sslErrorsOccurred, sMainNAM, &QgsNetworkAccessManager::handleSslErrors );
669 connect(
this, &QNetworkAccessManager::authenticationRequired,
this, &QgsNetworkAccessManager::onAuthRequired );
670 connect(
this, &QgsNetworkAccessManager::authRequestOccurred, sMainNAM, &QgsNetworkAccessManager::handleAuthRequest );
672 connect(
this, &QNetworkAccessManager::finished,
this, &QgsNetworkAccessManager::onReplyFinished );
677 QStringList excludes;
678 QStringList noProxyURLs;
680 const bool proxyEnabled = settings.
value( QStringLiteral(
"proxy/proxyEnabled" ),
false ).toBool();
685 excludes = settings.
value( QStringLiteral(
"proxy/proxyExcludedUrls" ), QStringList() ).toStringList();
687 noProxyURLs = settings.
value( QStringLiteral(
"proxy/noProxyUrls" ), QStringList() ).toStringList();
690 const QString proxyHost = settings.
value( QStringLiteral(
"proxy/proxyHost" ),
"" ).toString();
691 const int proxyPort = settings.
value( QStringLiteral(
"proxy/proxyPort" ),
"" ).toString().toInt();
693 const QString proxyUser = settings.
value( QStringLiteral(
"proxy/proxyUser" ),
"" ).toString();
694 const QString proxyPassword = settings.
value( QStringLiteral(
"proxy/proxyPassword" ),
"" ).toString();
696 const QString proxyTypeString = settings.
value( QStringLiteral(
"proxy/proxyType" ),
"" ).toString();
698 if ( proxyTypeString == QLatin1String(
"DefaultProxy" ) )
700 mUseSystemProxy =
true;
701 QNetworkProxyFactory::setUseSystemConfiguration(
true );
702 QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery();
703 if ( !proxies.isEmpty() )
705 proxy = proxies.first();
711 QNetworkProxy::ProxyType proxyType = QNetworkProxy::DefaultProxy;
712 if ( proxyTypeString == QLatin1String(
"Socks5Proxy" ) )
714 proxyType = QNetworkProxy::Socks5Proxy;
716 else if ( proxyTypeString == QLatin1String(
"HttpProxy" ) )
718 proxyType = QNetworkProxy::HttpProxy;
720 else if ( proxyTypeString == QLatin1String(
"HttpCachingProxy" ) )
722 proxyType = QNetworkProxy::HttpCachingProxy;
724 else if ( proxyTypeString == QLatin1String(
"FtpCachingProxy" ) )
726 proxyType = QNetworkProxy::FtpCachingProxy;
728 QgsDebugMsg( QStringLiteral(
"setting proxy %1 %2:%3 %4/%5" )
730 .arg( proxyHost ).arg( proxyPort )
731 .arg( proxyUser, proxyPassword )
733 proxy = QNetworkProxy( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword );
736 const QString authcfg = settings.
value( QStringLiteral(
"proxy/authcfg" ),
"" ).toString();
737 if ( !authcfg.isEmpty( ) )
739 QgsDebugMsg( QStringLiteral(
"setting proxy from stored authentication configuration %1" ).arg( authcfg ) );
752 QString cacheDirectory = settings.
value( QStringLiteral(
"cache/directory" ) ).toString();
753 if ( cacheDirectory.isEmpty() )
754 cacheDirectory = QStandardPaths::writableLocation( QStandardPaths::CacheLocation );
755 const qint64 cacheSize = settings.
value( QStringLiteral(
"cache/size" ), 256 * 1024 * 1024 ).toLongLong();
761 if ( cache() != newcache )
762 setCache( newcache );
764 if (
this != sMainNAM )
766 static_cast<QgsNetworkCookieJar *
>( cookieJar() )->setAllCookies(
static_cast<QgsNetworkCookieJar *
>( sMainNAM->cookieJar() )->allCookies() );
770 void QgsNetworkAccessManager::syncCookies(
const QList<QNetworkCookie> &cookies )
772 if ( sender() !=
this )
774 static_cast<QgsNetworkCookieJar *
>( cookieJar() )->setAllCookies( cookies );
775 if (
this == sMainNAM )
796 br.
get( request, forceRefresh, feedback );
804 br.
post( request, data, forceRefresh, feedback );
810 QString
id = QUuid::createUuid().toString();
811 sCustomPreprocessors.emplace_back( std::make_pair(
id, processor ) );
817 const size_t prevCount = sCustomPreprocessors.size();
818 sCustomPreprocessors.erase( std::remove_if( sCustomPreprocessors.begin(), sCustomPreprocessors.end(), [
id]( std::pair< QString, std::function<
void( QNetworkRequest * ) > > &a )
820 return a.first == id;
821 } ), sCustomPreprocessors.end() );
822 return prevCount != sCustomPreprocessors.size();
827 for (
const auto &preprocessor : sCustomPreprocessors )
829 preprocessor.second( req );
839 : mOperation( operation )
840 , mRequest( request )
841 , mOriginatingThreadId( QStringLiteral(
"0x%2" ).arg( reinterpret_cast<quintptr>( QThread::currentThread() ), 2 * QT_POINTER_SIZE, 16, QLatin1Char(
'0' ) ) )
842 , mRequestId( requestId )
843 , mContent( content )
844 , mInitiatorClass( request.attribute( static_cast< QNetworkRequest::Attribute >(
QgsNetworkRequestParameters::AttributeInitiatorClass ) ).toString() )
845 , mInitiatorRequestId( request.attribute( static_cast< QNetworkRequest::Attribute >(
QgsNetworkRequestParameters::AttributeInitiatorRequestId ) ) )
857 QgsDebugMsg( QStringLiteral(
"SSL errors occurred accessing URL:\n%1" ).arg( reply->request().url().toString() ) );
867 QgsDebugMsg( QStringLiteral(
"Network reply required authentication, but no handler was in place to provide this authentication request while accessing the URL:\n%1" ).arg( reply->request().url().toString() ) );
873 QgsDebugMsg( QStringLiteral(
"Network authentication required external browser to open URL %1, but no handler was in place" ).arg( url.toString() ) );
878 QgsDebugMsg( QStringLiteral(
"Network authentication required external browser closed, but no handler was in place" ) );
882 #include "qgsnetworkaccessmanager.moc"
static int versionInt()
Version number used for comparing versions using the "Check QGIS Version" function.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
static QList< QSslCertificate > casMerge(const QList< QSslCertificate > &bundle1, const QList< QSslCertificate > &bundle2)
casMerge merges two certificate bundles in a single one removing duplicates, the certificates from th...
Configuration container for SSL server connection exceptions or overrides.
QSsl::SslProtocol sslProtocol() const
SSL server protocol to use in connections.
int sslPeerVerifyDepth() const
Number or SSL client's peer to verify in connections.
bool isNull() const
Whether configuration is null (missing components)
QSslSocket::PeerVerifyMode sslPeerVerifyMode() const
SSL client's peer verify mode to use in connections.
bool updateNetworkProxy(QNetworkProxy &proxy, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QNetworkProxy with an authentication config.
const QgsAuthConfigSslServer sslCertCustomConfigByHost(const QString &hostport)
sslCertCustomConfigByHost get an SSL certificate custom config by hostport (host:port)
A thread safe class for performing blocking (sync) network requests, with full support for QGIS proxy...
ErrorCode get(QNetworkRequest &request, bool forceRefresh=false, QgsFeedback *feedback=nullptr)
Performs a "get" operation on the specified request.
ErrorCode post(QNetworkRequest &request, QIODevice *data, bool forceRefresh=false, QgsFeedback *feedback=nullptr)
Performs a "post" operation on the specified request, using the given data.
void setAuthCfg(const QString &authCfg)
Sets the authentication config id which should be used during the request.
QgsNetworkReplyContent reply() const
Returns the content of the network reply, after a get() or post() request has been made.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
network access manager for QGIS
QStringList noProxyList() const
Returns the no proxy list.
void finished(QgsNetworkReplyContent reply)
Emitted whenever a pending network reply is finished.
void cookiesChanged(const QList< QNetworkCookie > &cookies)
Emitted when the cookies changed.
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 QgsNetworkReplyCon...
void insertProxyFactory(QNetworkProxyFactory *factory)
Inserts a factory into the proxy factories list.
void setSslErrorHandler(std::unique_ptr< QgsSslErrorHandler > handler)
Sets the application SSL error handler, which is used to respond to SSL errors encountered during net...
void abortAuthBrowser()
Abort any outstanding external browser login request.
void setCacheDisabled(bool disabled)
Sets whether all network caching should be disabled.
const QList< QNetworkProxyFactory * > proxyFactories() const
Returns a list of proxy factories used by the manager.
void downloadProgress(int requestId, qint64 bytesReceived, qint64 bytesTotal)
Emitted when a network reply receives a progress report.
void requestAuthOpenBrowser(const QUrl &url) const
Forwards an external browser login url opening request to the authentication handler.
void requestAuthCloseBrowser() const
Forwards an external browser login closure request to the authentication handler.
void requestEncounteredSslErrors(int requestId, const QList< QSslError > &errors)
Emitted when a network request encounters SSL errors.
static QString cacheLoadControlName(QNetworkRequest::CacheLoadControl control)
Returns the name for QNetworkRequest::CacheLoadControl.
static const QgsSettingsEntryInteger settingsNetworkTimeout
Settings entry network timeout.
static bool removeRequestPreprocessor(const QString &id)
Removes the custom pre-processor function with matching id.
void requestAuthDetailsAdded(int requestId, const QString &realm, const QString &user, const QString &password)
Emitted when network authentication details have been added to a request.
static QNetworkRequest::CacheLoadControl cacheLoadControlFromName(const QString &name)
Returns QNetworkRequest::CacheLoadControl from a name.
bool cacheDisabled() const
Returns true if all network caching is disabled.
QgsNetworkAccessManager(QObject *parent=nullptr)
void requestRequiresAuth(int requestId, const QString &realm)
Emitted when a network request prompts an authentication request.
void preprocessRequest(QNetworkRequest *req) const
Preprocesses request.
void setAuthHandler(std::unique_ptr< QgsNetworkAuthenticationHandler > handler)
Sets the application network authentication handler, which is used to respond to network authenticati...
static void setTimeout(int time)
Sets the maximum timeout time for network requests, in milliseconds.
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,...
const QNetworkProxy & fallbackProxy() const
Returns the fallback proxy used by the manager.
static int timeout()
Returns the network timeout length, in milliseconds.
void setupDefaultProxyAndCache(Qt::ConnectionType connectionType=Qt::BlockingQueuedConnection)
Setup the QgsNetworkAccessManager (NAM) according to the user's settings.
static QString setRequestPreprocessor(const std::function< void(QNetworkRequest *request)> &processor)
Sets a request pre-processor function, which allows manipulation of a network request before it is pr...
void setFallbackProxyAndExcludes(const QNetworkProxy &proxy, const QStringList &excludes, const QStringList &noProxyURLs)
Sets the fallback proxy and URLs which shouldn't use it.
Q_DECL_DEPRECATED void requestCreated(QNetworkReply *)
Q_DECL_DEPRECATED void requestAboutToBeCreated(QNetworkAccessManager::Operation, const QNetworkRequest &, QIODevice *)
QStringList excludeList() const
Returns the proxy exclude list.
static QgsNetworkAccessManager * instance(Qt::ConnectionType connectionType=Qt::BlockingQueuedConnection)
Returns a pointer to the active QgsNetworkAccessManager for the current thread.
void removeProxyFactory(QNetworkProxyFactory *factory)
Removes a factory from the proxy factories list.
void authBrowserAborted()
Emitted when external browser logins are to be aborted.
void requestTimedOut(QgsNetworkRequestParameters request)
Emitted when a network request has timed out.
bool useSystemProxy() const
Returns whether the system proxy should be used.
QNetworkReply * createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *outgoingData=nullptr) override
virtual void handleAuthRequest(QNetworkReply *reply, QAuthenticator *auth)
Called whenever network authentication requests are encountered during a network reply.
virtual void handleAuthRequestCloseBrowser()
Called to terminate a network authentication through external browser.
virtual void handleAuthRequestOpenBrowser(const QUrl &url)
Called to initiate a network authentication through external browser url.
Wrapper implementation of QNetworkDiskCache with all methods guarded by a mutex soly for internal use...
void setCacheDirectory(const QString &cacheDir)
qint64 maximumCacheSize() const
void setMaximumCacheSize(qint64 size)
QString cacheDirectory() const
Encapsulates a network reply within a container which is inexpensive to copy and safe to pass between...
Encapsulates parameters and properties of a network request.
QgsNetworkRequestParameters()=default
Default constructor.
bool setValue(qlonglong value, const QString &dynamicKeyPart=QString()) const
Set settings value.
qlonglong value(const QString &dynamicKeyPart=QString(), bool useDefaultValueOverride=false, qlonglong defaultValueOverride=0) const
Returns settings value.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
virtual void handleSslErrors(QNetworkReply *reply, const QList< QSslError > &errors)
Called whenever SSL errors are encountered during a network reply.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
#define QgsDebugMsgLevel(str, level)