39#include <QNetworkReply>
40#include <QRecursiveMutex>
41#include <QThreadStorage>
42#include <QAuthenticator>
43#include <QStandardPaths>
49#include <QSslConfiguration>
57static std::vector< std::pair< QString, std::function< void( QNetworkRequest * ) > > > sCustomPreprocessors;
58static std::vector< std::pair< QString, std::function< void(
const QNetworkRequest &, QNetworkReply * ) > > > sCustomReplyPreprocessors;
61class QgsNetworkProxyFactory :
public QNetworkProxyFactory
64 QgsNetworkProxyFactory() =
default;
66 QList<QNetworkProxy> queryProxy(
const QNetworkProxyQuery &query = QNetworkProxyQuery() )
override
72 for ( QNetworkProxyFactory *f : constProxyFactories )
74 QList<QNetworkProxy> systemproxies = QNetworkProxyFactory::systemProxyForQuery( query );
75 if ( !systemproxies.isEmpty() )
78 QList<QNetworkProxy> proxies = f->queryProxy( query );
79 if ( !proxies.isEmpty() )
84 if ( query.queryType() != QNetworkProxyQuery::UrlRequest )
87 const QString url = query.url().toString();
90 for (
const QString &noProxy : constNoProxyList )
92 if ( !noProxy.trimmed().isEmpty() && url.startsWith( noProxy ) )
94 QgsDebugMsgLevel( QStringLiteral(
"don't using any proxy for %1 [exclude %2]" ).arg( url, noProxy ), 4 );
95 return QList<QNetworkProxy>() << QNetworkProxy( QNetworkProxy::NoProxy );
100 for (
const QString &exclude : constExcludeList )
102 if ( !exclude.trimmed().isEmpty() && url.startsWith( exclude ) )
104 QgsDebugMsgLevel( QStringLiteral(
"using default proxy for %1 [exclude %2]" ).arg( url, exclude ), 4 );
105 return QList<QNetworkProxy>() << QNetworkProxy( QNetworkProxy::DefaultProxy );
111 QgsDebugMsgLevel( QStringLiteral(
"requesting system proxy for query %1" ).arg( url ), 4 );
112 QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery( query );
113 if ( !proxies.isEmpty() )
116 .arg( proxies.first().hostName() ).arg( proxies.first().port() ), 4 );
121 QgsDebugMsgLevel( QStringLiteral(
"using fallback proxy for %1" ).arg( url ), 4 );
128class QgsNetworkCookieJar :
public QNetworkCookieJar
134 : QNetworkCookieJar( parent )
138 bool deleteCookie(
const QNetworkCookie &cookie )
override
140 const QMutexLocker locker( &mMutex );
141 if ( QNetworkCookieJar::deleteCookie( cookie ) )
143 emit mNam->cookiesChanged( allCookies() );
148 bool insertCookie(
const QNetworkCookie &cookie )
override
150 const QMutexLocker locker( &mMutex );
151 if ( QNetworkCookieJar::insertCookie( cookie ) )
153 emit mNam->cookiesChanged( allCookies() );
158 bool setCookiesFromUrl(
const QList<QNetworkCookie> &cookieList,
const QUrl &url )
override
160 const QMutexLocker locker( &mMutex );
161 return QNetworkCookieJar::setCookiesFromUrl( cookieList, url );
163 bool updateCookie(
const QNetworkCookie &cookie )
override
165 const QMutexLocker locker( &mMutex );
166 if ( QNetworkCookieJar::updateCookie( cookie ) )
168 emit mNam->cookiesChanged( allCookies() );
175 QList<QNetworkCookie> allCookies()
const
177 const QMutexLocker locker( &mMutex );
178 return QNetworkCookieJar::allCookies();
180 void setAllCookies(
const QList<QNetworkCookie> &cookieList )
182 const QMutexLocker locker( &mMutex );
183 QNetworkCookieJar::setAllCookies( cookieList );
187 mutable QRecursiveMutex mMutex;
197 static QThreadStorage<QgsNetworkAccessManager> sInstances;
200 if ( nam->thread() == qApp->thread() )
203 if ( !nam->mInitialized )
213 : QNetworkAccessManager( parent )
214 , mSslErrorHandlerSemaphore( 1 )
215 , mAuthRequestHandlerSemaphore( 1 )
217 setProxyFactory(
new QgsNetworkProxyFactory() );
218 setCookieJar(
new QgsNetworkCookieJar(
this ) );
223 Q_ASSERT( sMainNAM ==
this );
224 mSslErrorHandler = std::move( handler );
229 Q_ASSERT( sMainNAM ==
this );
230 mAuthHandler = std::move( handler );
235 mProxyFactories.insert( 0, factory );
240 mProxyFactories.removeAll( factory );
245 return mProxyFactories;
250 return mExcludedURLs;
260 return mFallbackProxy;
265 QgsDebugMsgLevel( QStringLiteral(
"proxy settings: (type:%1 host: %2:%3, user:%4, password:%5" )
266 .arg( proxy.type() == QNetworkProxy::DefaultProxy ? QStringLiteral(
"DefaultProxy" ) :
267 proxy.type() == QNetworkProxy::Socks5Proxy ? QStringLiteral(
"Socks5Proxy" ) :
268 proxy.type() == QNetworkProxy::NoProxy ? QStringLiteral(
"NoProxy" ) :
269 proxy.type() == QNetworkProxy::HttpProxy ? QStringLiteral(
"HttpProxy" ) :
270 proxy.type() == QNetworkProxy::HttpCachingProxy ? QStringLiteral(
"HttpCachingProxy" ) :
271 proxy.type() == QNetworkProxy::FtpCachingProxy ? QStringLiteral(
"FtpCachingProxy" ) :
272 QStringLiteral(
"Undefined" ),
276 proxy.password().isEmpty() ? QStringLiteral(
"not set" ) : QStringLiteral(
"set" ) ), 4 );
278 mFallbackProxy = proxy;
279 mExcludedURLs = excludes;
281 mExcludedURLs.erase( std::remove_if( mExcludedURLs.begin(), mExcludedURLs.end(),
282 [](
const QString & url )
284 return url.trimmed().isEmpty();
285 } ), mExcludedURLs.end() );
287 mNoProxyURLs = noProxyURLs;
288 mNoProxyURLs.erase( std::remove_if( mNoProxyURLs.begin(), mNoProxyURLs.end(),
289 [](
const QString & url )
291 return url.trimmed().isEmpty();
292 } ), mNoProxyURLs.end() );
299 QNetworkRequest *pReq(
const_cast< QNetworkRequest *
>( &req ) );
301 QString userAgent = s.
value( QStringLiteral(
"/qgis/networkAndProxy/userAgent" ),
"Mozilla/5.0" ).toString();
302 if ( !userAgent.isEmpty() )
304 userAgent += QStringLiteral(
"QGIS/%1/%2" ).arg(
Qgis::versionInt() ).arg( QSysInfo::prettyProductName() );
305 pReq->setRawHeader(
"User-Agent", userAgent.toLatin1() );
308 const bool ishttps = pReq->url().scheme().compare( QLatin1String(
"https" ), Qt::CaseInsensitive ) == 0;
311 QgsDebugMsgLevel( QStringLiteral(
"Adding trusted CA certs to request" ), 3 );
312 QSslConfiguration sslconfig( pReq->sslConfiguration() );
316 const QString hostport( QStringLiteral(
"%1:%2" )
317 .arg( pReq->url().host().trimmed() )
318 .arg( pReq->url().port() != -1 ? pReq->url().port() : 443 ) );
320 if ( !servconfig.
isNull() )
322 QgsDebugMsgLevel( QStringLiteral(
"Adding SSL custom config to request for %1" ).arg( hostport ), 2 );
328 pReq->setSslConfiguration( sslconfig );
332 if ( sMainNAM->mCacheDisabled )
335 pReq->setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork );
336 pReq->setAttribute( QNetworkRequest::CacheSaveControlAttribute,
false );
339 for (
const auto &preprocessor : sCustomPreprocessors )
341 preprocessor.second( pReq );
344 static QAtomicInt sRequestId = 0;
345 const int requestId = ++sRequestId;
347 if ( QBuffer *buffer = qobject_cast<QBuffer *>( outgoingData ) )
349 content = buffer->buffer();
356 QNetworkReply *reply = QNetworkAccessManager::createRequest( op, req, outgoingData );
357 reply->setProperty(
"requestId", requestId );
363 connect( reply, &QNetworkReply::downloadProgress,
this, &QgsNetworkAccessManager::onReplyDownloadProgress );
365 connect( reply, &QNetworkReply::sslErrors,
this, &QgsNetworkAccessManager::onReplySslErrors );
368 for (
const auto &replyPreprocessor : sCustomReplyPreprocessors )
370 replyPreprocessor.second( req, reply );
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 );
393void QgsNetworkAccessManager::abortRequest()
395 QTimer *timer = qobject_cast<QTimer *>( sender() );
398 QNetworkReply *reply = qobject_cast<QNetworkReply *>( timer->parent() );
402 QgsDebugMsgLevel( QStringLiteral(
"Abort [reply:%1] %2" ).arg(
reinterpret_cast< qint64
>( reply ), 0, 16 ).arg( reply->url().toString() ), 3 );
409void QgsNetworkAccessManager::onReplyFinished( QNetworkReply *reply )
414void QgsNetworkAccessManager::onReplyDownloadProgress( qint64 bytesReceived, qint64 bytesTotal )
416 if ( QNetworkReply *reply = qobject_cast< QNetworkReply *>( sender() ) )
423void QgsNetworkAccessManager::onReplySslErrors(
const QList<QSslError> &errors )
425 QNetworkReply *reply = qobject_cast< QNetworkReply *>( sender() );
427 Q_ASSERT( reply->manager() ==
this );
429 QgsDebugMsgLevel( QStringLiteral(
"Stopping network reply timeout whilst SSL error is handled" ), 2 );
430 pauseTimeout( reply );
435 mSslErrorHandlerSemaphore.acquire();
439 emit sslErrorsOccurred( reply, errors );
440 if (
this != sMainNAM )
444 mSslErrorHandlerSemaphore.acquire();
445 mSslErrorHandlerSemaphore.release();
446 afterSslErrorHandled( reply );
450void QgsNetworkAccessManager::afterSslErrorHandled( QNetworkReply *reply )
452 if ( reply->manager() ==
this )
454 restartTimeout( reply );
455 emit sslErrorsHandled( reply );
459void QgsNetworkAccessManager::afterAuthRequestHandled( QNetworkReply *reply )
461 if ( reply->manager() ==
this )
463 restartTimeout( reply );
464 emit authRequestHandled( reply );
468void QgsNetworkAccessManager::pauseTimeout( QNetworkReply *reply )
470 Q_ASSERT( reply->manager() ==
this );
472 QTimer *timer = reply->findChild<QTimer *>( QStringLiteral(
"timeoutTimer" ) );
473 if ( timer && timer->isActive() )
479void QgsNetworkAccessManager::restartTimeout( QNetworkReply *reply )
481 Q_ASSERT( reply->manager() ==
this );
483 QTimer *timer = reply->findChild<QTimer *>( QStringLiteral(
"timeoutTimer" ) );
486 Q_ASSERT( !timer->isActive() );
487 QgsDebugMsgLevel( QStringLiteral(
"Restarting network reply timeout" ), 2 );
488 timer->setSingleShot(
true );
493int QgsNetworkAccessManager::getRequestId( QNetworkReply *reply )
495 return reply->property(
"requestId" ).toInt();
498void QgsNetworkAccessManager::handleSslErrors( QNetworkReply *reply,
const QList<QSslError> &errors )
500 mSslErrorHandler->handleSslErrors( reply, errors );
501 afterSslErrorHandled( reply );
502 qobject_cast<QgsNetworkAccessManager *>( reply->manager() )->mSslErrorHandlerSemaphore.release();
507void QgsNetworkAccessManager::onAuthRequired( QNetworkReply *reply, QAuthenticator *auth )
510 Q_ASSERT( reply->manager() ==
this );
512 QgsDebugMsgLevel( QStringLiteral(
"Stopping network reply timeout whilst auth request is handled" ), 2 );
513 pauseTimeout( reply );
518 mAuthRequestHandlerSemaphore.acquire();
522 emit authRequestOccurred( reply, auth );
524 if (
this != sMainNAM )
528 mAuthRequestHandlerSemaphore.acquire();
529 mAuthRequestHandlerSemaphore.release();
530 afterAuthRequestHandled( reply );
536 if (
this != sMainNAM )
542 mAuthHandler->handleAuthRequestOpenBrowser( url );
547 if (
this != sMainNAM )
553 mAuthHandler->handleAuthRequestCloseBrowser();
558 if (
this != sMainNAM )
565void QgsNetworkAccessManager::handleAuthRequest( QNetworkReply *reply, QAuthenticator *auth )
567 mAuthHandler->handleAuthRequest( reply, auth );
571 afterAuthRequestHandled( reply );
572 qobject_cast<QgsNetworkAccessManager *>( reply->manager() )->mAuthRequestHandlerSemaphore.release();
579 case QNetworkRequest::AlwaysNetwork:
580 return QStringLiteral(
"AlwaysNetwork" );
581 case QNetworkRequest::PreferNetwork:
582 return QStringLiteral(
"PreferNetwork" );
583 case QNetworkRequest::PreferCache:
584 return QStringLiteral(
"PreferCache" );
585 case QNetworkRequest::AlwaysCache:
586 return QStringLiteral(
"AlwaysCache" );
588 return QStringLiteral(
"PreferNetwork" );
593 if ( name == QLatin1String(
"AlwaysNetwork" ) )
595 return QNetworkRequest::AlwaysNetwork;
597 else if ( name == QLatin1String(
"PreferNetwork" ) )
599 return QNetworkRequest::PreferNetwork;
601 else if ( name == QLatin1String(
"PreferCache" ) )
603 return QNetworkRequest::PreferCache;
605 else if ( name == QLatin1String(
"AlwaysCache" ) )
607 return QNetworkRequest::AlwaysCache;
609 return QNetworkRequest::PreferNetwork;
615 mUseSystemProxy =
false;
617 Q_ASSERT( sMainNAM );
619 if ( sMainNAM !=
this )
621 connect(
this, &QNetworkAccessManager::proxyAuthenticationRequired,
622 sMainNAM, &QNetworkAccessManager::proxyAuthenticationRequired,
640 connect(
this, &QNetworkAccessManager::sslErrors,
641 sMainNAM, &QNetworkAccessManager::sslErrors,
654 if ( !mSslErrorHandler )
658 setAuthHandler( std::make_unique< QgsNetworkAuthenticationHandler>() );
661 connect(
this, &QgsNetworkAccessManager::sslErrorsOccurred, sMainNAM, &QgsNetworkAccessManager::handleSslErrors );
663 connect(
this, &QNetworkAccessManager::authenticationRequired,
this, &QgsNetworkAccessManager::onAuthRequired );
664 connect(
this, &QgsNetworkAccessManager::authRequestOccurred, sMainNAM, &QgsNetworkAccessManager::handleAuthRequest );
666 connect(
this, &QNetworkAccessManager::finished,
this, &QgsNetworkAccessManager::onReplyFinished );
671 QStringList excludes;
672 QStringList noProxyURLs;
674 const bool proxyEnabled = settings.
value( QStringLiteral(
"proxy/proxyEnabled" ),
false ).toBool();
679 excludes = settings.
value( QStringLiteral(
"proxy/proxyExcludedUrls" ), QStringList() ).toStringList();
681 noProxyURLs = settings.
value( QStringLiteral(
"proxy/noProxyUrls" ), QStringList() ).toStringList();
684 const QString proxyHost = settings.
value( QStringLiteral(
"proxy/proxyHost" ),
"" ).toString();
685 const int proxyPort = settings.
value( QStringLiteral(
"proxy/proxyPort" ),
"" ).toString().toInt();
687 const QString proxyUser = settings.
value( QStringLiteral(
"proxy/proxyUser" ),
"" ).toString();
688 const QString proxyPassword = settings.
value( QStringLiteral(
"proxy/proxyPassword" ),
"" ).toString();
690 const QString proxyTypeString = settings.
value( QStringLiteral(
"proxy/proxyType" ),
"" ).toString();
692 if ( proxyTypeString == QLatin1String(
"DefaultProxy" ) )
694 mUseSystemProxy =
true;
695 QNetworkProxyFactory::setUseSystemConfiguration(
true );
696 QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery();
697 if ( !proxies.isEmpty() )
699 proxy = proxies.first();
705 QNetworkProxy::ProxyType proxyType = QNetworkProxy::DefaultProxy;
706 if ( proxyTypeString == QLatin1String(
"Socks5Proxy" ) )
708 proxyType = QNetworkProxy::Socks5Proxy;
710 else if ( proxyTypeString == QLatin1String(
"HttpProxy" ) )
712 proxyType = QNetworkProxy::HttpProxy;
714 else if ( proxyTypeString == QLatin1String(
"HttpCachingProxy" ) )
716 proxyType = QNetworkProxy::HttpCachingProxy;
718 else if ( proxyTypeString == QLatin1String(
"FtpCachingProxy" ) )
720 proxyType = QNetworkProxy::FtpCachingProxy;
724 .arg( proxyHost ).arg( proxyPort )
725 .arg( proxyUser, proxyPassword ), 2
727 proxy = QNetworkProxy( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword );
730 const QString authcfg = settings.
value( QStringLiteral(
"proxy/authcfg" ),
"" ).toString();
731 if ( !authcfg.isEmpty( ) )
733 QgsDebugMsgLevel( QStringLiteral(
"setting proxy from stored authentication configuration %1" ).arg( authcfg ), 2 );
736 authManager->updateNetworkProxy( proxy, authcfg );
746 QString cacheDirectory = settings.
value( QStringLiteral(
"cache/directory" ) ).toString();
747 if ( cacheDirectory.isEmpty() )
748 cacheDirectory = QStandardPaths::writableLocation( QStandardPaths::CacheLocation );
749 const qint64 cacheSize = settings.
value( QStringLiteral(
"cache/size" ), 256 * 1024 * 1024 ).toLongLong();
755 if ( cache() != newcache )
756 setCache( newcache );
758 if (
this != sMainNAM )
760 static_cast<QgsNetworkCookieJar *
>( cookieJar() )->setAllCookies(
static_cast<QgsNetworkCookieJar *
>( sMainNAM->cookieJar() )->allCookies() );
764void QgsNetworkAccessManager::syncCookies(
const QList<QNetworkCookie> &cookies )
766 if ( sender() !=
this )
768 static_cast<QgsNetworkCookieJar *
>( cookieJar() )->setAllCookies( cookies );
769 if (
this == sMainNAM )
790 br.
get( request, forceRefresh, feedback );
798 br.
post( request, data, forceRefresh, feedback );
804 QString
id = QUuid::createUuid().toString();
805 sCustomPreprocessors.emplace_back( std::make_pair(
id, processor ) );
811 const size_t prevCount = sCustomPreprocessors.size();
812 sCustomPreprocessors.erase( std::remove_if( sCustomPreprocessors.begin(), sCustomPreprocessors.end(), [
id]( std::pair< QString, std::function<
void( QNetworkRequest * ) > > &a )
814 return a.first == id;
815 } ), sCustomPreprocessors.end() );
816 return prevCount != sCustomPreprocessors.size();
821 QString
id = QUuid::createUuid().toString();
822 sCustomReplyPreprocessors.emplace_back( std::make_pair(
id, processor ) );
828 const size_t prevCount = sCustomReplyPreprocessors.size();
829 sCustomReplyPreprocessors.erase( std::remove_if( sCustomReplyPreprocessors.begin(), sCustomReplyPreprocessors.end(), [
id]( std::pair< QString, std::function<
void(
const QNetworkRequest &, QNetworkReply * ) > > &a )
831 return a.first == id;
832 } ), sCustomReplyPreprocessors.end() );
833 return prevCount != sCustomReplyPreprocessors.size();
838 for (
const auto &preprocessor : sCustomPreprocessors )
840 preprocessor.second( req );
850 : mOperation( operation )
851 , mRequest( request )
852 , mOriginatingThreadId( QStringLiteral(
"0x%2" ).arg( reinterpret_cast<quintptr>( QThread::currentThread() ), 2 * QT_POINTER_SIZE, 16, QLatin1Char(
'0' ) ) )
853 , mRequestId( requestId )
854 , mContent( content )
855 , mInitiatorClass( request.attribute( static_cast< QNetworkRequest::Attribute >(
QgsNetworkRequestParameters::AttributeInitiatorClass ) ).toString() )
856 , mInitiatorRequestId( request.attribute( static_cast< QNetworkRequest::Attribute >(
QgsNetworkRequestParameters::AttributeInitiatorRequestId ) ) )
868 QgsDebugError( QStringLiteral(
"SSL errors occurred accessing URL:\n%1" ).arg( reply->request().url().toString() ) );
878 QgsDebugError( 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() ) );
884 QgsDebugError( QStringLiteral(
"Network authentication required external browser to open URL %1, but no handler was in place" ).arg( url.toString() ) );
889 QgsDebugError( QStringLiteral(
"Network authentication required external browser closed, but no handler was in place" ) );
893#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.
Singleton offering an interface to manage the authentication configuration database and to utilize co...
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(), post(), head() or put() request has been mad...
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.
static const QgsSettingsEntryInteger * settingsNetworkTimeout
Settings entry network timeout.
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 QString setReplyPreprocessor(const std::function< void(const QNetworkRequest &, QNetworkReply *)> &processor)
Sets a reply pre-processor function, which allows manipulation of QNetworkReply objects after they ar...
static bool removeRequestPreprocessor(const QString &id)
Removes the custom request 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 *)
static bool removeReplyPreprocessor(const QString &id)
Removes the custom reply pre-processor function with matching id.
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.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
An integer settings entry.
static QgsSettingsTreeNode * sTreeNetwork
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)
#define QgsDebugError(str)