37#include <QNetworkReply>
38#include <QRecursiveMutex>
39#include <QThreadStorage>
40#include <QAuthenticator>
41#include <QStandardPaths>
45#include <QSslConfiguration>
53static std::vector< std::pair< QString, std::function< void( QNetworkRequest * ) > > > sCustomPreprocessors;
54static std::vector< std::pair< QString, std::function< void(
const QNetworkRequest &, QNetworkReply * ) > > > sCustomReplyPreprocessors;
57class QgsNetworkProxyFactory :
public QNetworkProxyFactory
60 QgsNetworkProxyFactory() =
default;
62 QList<QNetworkProxy> queryProxy(
const QNetworkProxyQuery &query = QNetworkProxyQuery() )
override
68 for ( QNetworkProxyFactory *f : constProxyFactories )
70 QList<QNetworkProxy> systemproxies = QNetworkProxyFactory::systemProxyForQuery( query );
71 if ( !systemproxies.isEmpty() )
74 QList<QNetworkProxy> proxies = f->queryProxy( query );
75 if ( !proxies.isEmpty() )
80 if ( query.queryType() != QNetworkProxyQuery::UrlRequest )
83 const QString url = query.url().toString();
86 for (
const QString &noProxy : constNoProxyList )
88 if ( !noProxy.trimmed().isEmpty() && url.startsWith( noProxy ) )
90 QgsDebugMsgLevel( QStringLiteral(
"don't using any proxy for %1 [exclude %2]" ).arg( url, noProxy ), 4 );
91 return QList<QNetworkProxy>() << QNetworkProxy( QNetworkProxy::NoProxy );
96 for (
const QString &exclude : constExcludeList )
98 if ( !exclude.trimmed().isEmpty() && url.startsWith( exclude ) )
100 QgsDebugMsgLevel( QStringLiteral(
"using default proxy for %1 [exclude %2]" ).arg( url, exclude ), 4 );
101 return QList<QNetworkProxy>() << QNetworkProxy( QNetworkProxy::DefaultProxy );
107 QgsDebugMsgLevel( QStringLiteral(
"requesting system proxy for query %1" ).arg( url ), 4 );
108 QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery( query );
109 if ( !proxies.isEmpty() )
112 .arg( proxies.first().hostName() ).arg( proxies.first().port() ), 4 );
117 QgsDebugMsgLevel( QStringLiteral(
"using fallback proxy for %1" ).arg( url ), 4 );
124class QgsNetworkCookieJar :
public QNetworkCookieJar
130 : QNetworkCookieJar( parent )
134 bool deleteCookie(
const QNetworkCookie &cookie )
override
136 const QMutexLocker locker( &mMutex );
137 if ( QNetworkCookieJar::deleteCookie( cookie ) )
139 emit mNam->cookiesChanged( allCookies() );
144 bool insertCookie(
const QNetworkCookie &cookie )
override
146 const QMutexLocker locker( &mMutex );
147 if ( QNetworkCookieJar::insertCookie( cookie ) )
149 emit mNam->cookiesChanged( allCookies() );
154 bool setCookiesFromUrl(
const QList<QNetworkCookie> &cookieList,
const QUrl &url )
override
156 const QMutexLocker locker( &mMutex );
157 return QNetworkCookieJar::setCookiesFromUrl( cookieList, url );
159 bool updateCookie(
const QNetworkCookie &cookie )
override
161 const QMutexLocker locker( &mMutex );
162 if ( QNetworkCookieJar::updateCookie( cookie ) )
164 emit mNam->cookiesChanged( allCookies() );
171 QList<QNetworkCookie> allCookies()
const
173 const QMutexLocker locker( &mMutex );
174 return QNetworkCookieJar::allCookies();
176 void setAllCookies(
const QList<QNetworkCookie> &cookieList )
178 const QMutexLocker locker( &mMutex );
179 QNetworkCookieJar::setAllCookies( cookieList );
183 mutable QRecursiveMutex mMutex;
193 static QThreadStorage<QgsNetworkAccessManager> sInstances;
196 if ( nam->thread() == qApp->thread() )
199 if ( !nam->mInitialized )
209 : QNetworkAccessManager( parent )
210 , mSslErrorHandlerSemaphore( 1 )
211 , mAuthRequestHandlerSemaphore( 1 )
213 setProxyFactory(
new QgsNetworkProxyFactory() );
214 setCookieJar(
new QgsNetworkCookieJar(
this ) );
219 Q_ASSERT( sMainNAM ==
this );
220 mSslErrorHandler = std::move( handler );
225 Q_ASSERT( sMainNAM ==
this );
226 mAuthHandler = std::move( handler );
231 mProxyFactories.insert( 0, factory );
236 mProxyFactories.removeAll( factory );
241 return mProxyFactories;
246 return mExcludedURLs;
256 return mFallbackProxy;
261 QgsDebugMsgLevel( QStringLiteral(
"proxy settings: (type:%1 host: %2:%3, user:%4, password:%5" )
262 .arg( proxy.type() == QNetworkProxy::DefaultProxy ? QStringLiteral(
"DefaultProxy" ) :
263 proxy.type() == QNetworkProxy::Socks5Proxy ? QStringLiteral(
"Socks5Proxy" ) :
264 proxy.type() == QNetworkProxy::NoProxy ? QStringLiteral(
"NoProxy" ) :
265 proxy.type() == QNetworkProxy::HttpProxy ? QStringLiteral(
"HttpProxy" ) :
266 proxy.type() == QNetworkProxy::HttpCachingProxy ? QStringLiteral(
"HttpCachingProxy" ) :
267 proxy.type() == QNetworkProxy::FtpCachingProxy ? QStringLiteral(
"FtpCachingProxy" ) :
268 QStringLiteral(
"Undefined" ),
272 proxy.password().isEmpty() ? QStringLiteral(
"not set" ) : QStringLiteral(
"set" ) ), 4 );
274 mFallbackProxy = proxy;
275 mExcludedURLs = excludes;
277 mExcludedURLs.erase( std::remove_if( mExcludedURLs.begin(), mExcludedURLs.end(),
278 [](
const QString & url )
280 return url.trimmed().isEmpty();
281 } ), mExcludedURLs.end() );
283 mNoProxyURLs = noProxyURLs;
284 mNoProxyURLs.erase( std::remove_if( mNoProxyURLs.begin(), mNoProxyURLs.end(),
285 [](
const QString & url )
287 return url.trimmed().isEmpty();
288 } ), mNoProxyURLs.end() );
295 QNetworkRequest *pReq(
const_cast< QNetworkRequest *
>( &req ) );
297 QString userAgent = s.
value( QStringLiteral(
"/qgis/networkAndProxy/userAgent" ),
"Mozilla/5.0" ).toString();
298 if ( !userAgent.isEmpty() )
300 userAgent += QStringLiteral(
"QGIS/%1/%2" ).arg(
Qgis::versionInt() ).arg( QSysInfo::prettyProductName() );
301 pReq->setRawHeader(
"User-Agent", userAgent.toLatin1() );
304 const bool ishttps = pReq->url().scheme().compare( QLatin1String(
"https" ), Qt::CaseInsensitive ) == 0;
307 QgsDebugMsgLevel( QStringLiteral(
"Adding trusted CA certs to request" ), 3 );
308 QSslConfiguration sslconfig( pReq->sslConfiguration() );
312 const QString hostport( QStringLiteral(
"%1:%2" )
313 .arg( pReq->url().host().trimmed() )
314 .arg( pReq->url().port() != -1 ? pReq->url().port() : 443 ) );
316 if ( !servconfig.
isNull() )
318 QgsDebugMsg( QStringLiteral(
"Adding SSL custom config to request for %1" ).arg( hostport ) );
324 pReq->setSslConfiguration( sslconfig );
328 if ( sMainNAM->mCacheDisabled )
331 pReq->setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork );
332 pReq->setAttribute( QNetworkRequest::CacheSaveControlAttribute,
false );
335 for (
const auto &preprocessor : sCustomPreprocessors )
337 preprocessor.second( pReq );
340 static QAtomicInt sRequestId = 0;
341 const int requestId = ++sRequestId;
343 if ( QBuffer *buffer = qobject_cast<QBuffer *>( outgoingData ) )
345 content = buffer->buffer();
352 QNetworkReply *reply = QNetworkAccessManager::createRequest( op, req, outgoingData );
353 reply->setProperty(
"requestId", requestId );
359 connect( reply, &QNetworkReply::downloadProgress,
this, &QgsNetworkAccessManager::onReplyDownloadProgress );
361 connect( reply, &QNetworkReply::sslErrors,
this, &QgsNetworkAccessManager::onReplySslErrors );
364 for (
const auto &replyPreprocessor : sCustomReplyPreprocessors )
366 replyPreprocessor.second( req, reply );
374 QTimer *timer =
new QTimer( reply );
375 timer->setObjectName( QStringLiteral(
"timeoutTimer" ) );
376 connect( timer, &QTimer::timeout,
this, &QgsNetworkAccessManager::abortRequest );
377 timer->setSingleShot(
true );
380 connect( reply, &QNetworkReply::downloadProgress, timer, [timer] { timer->start(); } );
381 connect( reply, &QNetworkReply::uploadProgress, timer, [timer] { timer->start(); } );
382 connect( reply, &QNetworkReply::finished, timer, &QTimer::stop );
384 QgsDebugMsgLevel( QStringLiteral(
"Created [reply:%1]" ).arg(
reinterpret_cast< qint64
>( reply ), 0, 16 ), 3 );
389void QgsNetworkAccessManager::abortRequest()
391 QTimer *timer = qobject_cast<QTimer *>( sender() );
394 QNetworkReply *reply = qobject_cast<QNetworkReply *>( timer->parent() );
398 QgsDebugMsgLevel( QStringLiteral(
"Abort [reply:%1] %2" ).arg(
reinterpret_cast< qint64
>( reply ), 0, 16 ).arg( reply->url().toString() ), 3 );
405void QgsNetworkAccessManager::onReplyFinished( QNetworkReply *reply )
410void QgsNetworkAccessManager::onReplyDownloadProgress( qint64 bytesReceived, qint64 bytesTotal )
412 if ( QNetworkReply *reply = qobject_cast< QNetworkReply *>( sender() ) )
419void QgsNetworkAccessManager::onReplySslErrors(
const QList<QSslError> &errors )
421 QNetworkReply *reply = qobject_cast< QNetworkReply *>( sender() );
423 Q_ASSERT( reply->manager() ==
this );
425 QgsDebugMsg( QStringLiteral(
"Stopping network reply timeout whilst SSL error is handled" ) );
426 pauseTimeout( reply );
431 mSslErrorHandlerSemaphore.acquire();
435 emit sslErrorsOccurred( reply, errors );
436 if (
this != sMainNAM )
440 mSslErrorHandlerSemaphore.acquire();
441 mSslErrorHandlerSemaphore.release();
442 afterSslErrorHandled( reply );
446void QgsNetworkAccessManager::afterSslErrorHandled( QNetworkReply *reply )
448 if ( reply->manager() ==
this )
450 restartTimeout( reply );
451 emit sslErrorsHandled( reply );
455void QgsNetworkAccessManager::afterAuthRequestHandled( QNetworkReply *reply )
457 if ( reply->manager() ==
this )
459 restartTimeout( reply );
460 emit authRequestHandled( reply );
464void QgsNetworkAccessManager::pauseTimeout( QNetworkReply *reply )
466 Q_ASSERT( reply->manager() ==
this );
468 QTimer *timer = reply->findChild<QTimer *>( QStringLiteral(
"timeoutTimer" ) );
469 if ( timer && timer->isActive() )
475void QgsNetworkAccessManager::restartTimeout( QNetworkReply *reply )
477 Q_ASSERT( reply->manager() ==
this );
479 QTimer *timer = reply->findChild<QTimer *>( QStringLiteral(
"timeoutTimer" ) );
482 Q_ASSERT( !timer->isActive() );
483 QgsDebugMsg( QStringLiteral(
"Restarting network reply timeout" ) );
484 timer->setSingleShot(
true );
489int QgsNetworkAccessManager::getRequestId( QNetworkReply *reply )
491 return reply->property(
"requestId" ).toInt();
494void QgsNetworkAccessManager::handleSslErrors( QNetworkReply *reply,
const QList<QSslError> &errors )
496 mSslErrorHandler->handleSslErrors( reply, errors );
497 afterSslErrorHandled( reply );
498 qobject_cast<QgsNetworkAccessManager *>( reply->manager() )->mSslErrorHandlerSemaphore.release();
503void QgsNetworkAccessManager::onAuthRequired( QNetworkReply *reply, QAuthenticator *auth )
506 Q_ASSERT( reply->manager() ==
this );
508 QgsDebugMsg( QStringLiteral(
"Stopping network reply timeout whilst auth request is handled" ) );
509 pauseTimeout( reply );
514 mAuthRequestHandlerSemaphore.acquire();
518 emit authRequestOccurred( reply, auth );
520 if (
this != sMainNAM )
524 mAuthRequestHandlerSemaphore.acquire();
525 mAuthRequestHandlerSemaphore.release();
526 afterAuthRequestHandled( reply );
532 if (
this != sMainNAM )
538 mAuthHandler->handleAuthRequestOpenBrowser( url );
543 if (
this != sMainNAM )
549 mAuthHandler->handleAuthRequestCloseBrowser();
554 if (
this != sMainNAM )
561void QgsNetworkAccessManager::handleAuthRequest( QNetworkReply *reply, QAuthenticator *auth )
563 mAuthHandler->handleAuthRequest( reply, auth );
567 afterAuthRequestHandled( reply );
568 qobject_cast<QgsNetworkAccessManager *>( reply->manager() )->mAuthRequestHandlerSemaphore.release();
575 case QNetworkRequest::AlwaysNetwork:
576 return QStringLiteral(
"AlwaysNetwork" );
577 case QNetworkRequest::PreferNetwork:
578 return QStringLiteral(
"PreferNetwork" );
579 case QNetworkRequest::PreferCache:
580 return QStringLiteral(
"PreferCache" );
581 case QNetworkRequest::AlwaysCache:
582 return QStringLiteral(
"AlwaysCache" );
584 return QStringLiteral(
"PreferNetwork" );
589 if ( name == QLatin1String(
"AlwaysNetwork" ) )
591 return QNetworkRequest::AlwaysNetwork;
593 else if ( name == QLatin1String(
"PreferNetwork" ) )
595 return QNetworkRequest::PreferNetwork;
597 else if ( name == QLatin1String(
"PreferCache" ) )
599 return QNetworkRequest::PreferCache;
601 else if ( name == QLatin1String(
"AlwaysCache" ) )
603 return QNetworkRequest::AlwaysCache;
605 return QNetworkRequest::PreferNetwork;
611 mUseSystemProxy =
false;
613 Q_ASSERT( sMainNAM );
615 if ( sMainNAM !=
this )
617 connect(
this, &QNetworkAccessManager::proxyAuthenticationRequired,
618 sMainNAM, &QNetworkAccessManager::proxyAuthenticationRequired,
636 connect(
this, &QNetworkAccessManager::sslErrors,
637 sMainNAM, &QNetworkAccessManager::sslErrors,
652 setAuthHandler( std::make_unique< QgsNetworkAuthenticationHandler>() );
655 connect(
this, &QgsNetworkAccessManager::sslErrorsOccurred, sMainNAM, &QgsNetworkAccessManager::handleSslErrors );
657 connect(
this, &QNetworkAccessManager::authenticationRequired,
this, &QgsNetworkAccessManager::onAuthRequired );
658 connect(
this, &QgsNetworkAccessManager::authRequestOccurred, sMainNAM, &QgsNetworkAccessManager::handleAuthRequest );
660 connect(
this, &QNetworkAccessManager::finished,
this, &QgsNetworkAccessManager::onReplyFinished );
665 QStringList excludes;
666 QStringList noProxyURLs;
668 const bool proxyEnabled = settings.
value( QStringLiteral(
"proxy/proxyEnabled" ),
false ).toBool();
673 excludes = settings.
value( QStringLiteral(
"proxy/proxyExcludedUrls" ), QStringList() ).toStringList();
675 noProxyURLs = settings.
value( QStringLiteral(
"proxy/noProxyUrls" ), QStringList() ).toStringList();
678 const QString proxyHost = settings.
value( QStringLiteral(
"proxy/proxyHost" ),
"" ).toString();
679 const int proxyPort = settings.
value( QStringLiteral(
"proxy/proxyPort" ),
"" ).toString().toInt();
681 const QString proxyUser = settings.
value( QStringLiteral(
"proxy/proxyUser" ),
"" ).toString();
682 const QString proxyPassword = settings.
value( QStringLiteral(
"proxy/proxyPassword" ),
"" ).toString();
684 const QString proxyTypeString = settings.
value( QStringLiteral(
"proxy/proxyType" ),
"" ).toString();
686 if ( proxyTypeString == QLatin1String(
"DefaultProxy" ) )
688 mUseSystemProxy =
true;
689 QNetworkProxyFactory::setUseSystemConfiguration(
true );
690 QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery();
691 if ( !proxies.isEmpty() )
693 proxy = proxies.first();
699 QNetworkProxy::ProxyType proxyType = QNetworkProxy::DefaultProxy;
700 if ( proxyTypeString == QLatin1String(
"Socks5Proxy" ) )
702 proxyType = QNetworkProxy::Socks5Proxy;
704 else if ( proxyTypeString == QLatin1String(
"HttpProxy" ) )
706 proxyType = QNetworkProxy::HttpProxy;
708 else if ( proxyTypeString == QLatin1String(
"HttpCachingProxy" ) )
710 proxyType = QNetworkProxy::HttpCachingProxy;
712 else if ( proxyTypeString == QLatin1String(
"FtpCachingProxy" ) )
714 proxyType = QNetworkProxy::FtpCachingProxy;
716 QgsDebugMsg( QStringLiteral(
"setting proxy %1 %2:%3 %4/%5" )
718 .arg( proxyHost ).arg( proxyPort )
719 .arg( proxyUser, proxyPassword )
721 proxy = QNetworkProxy( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword );
724 const QString authcfg = settings.
value( QStringLiteral(
"proxy/authcfg" ),
"" ).toString();
725 if ( !authcfg.isEmpty( ) )
727 QgsDebugMsg( QStringLiteral(
"setting proxy from stored authentication configuration %1" ).arg( authcfg ) );
740 QString cacheDirectory = settings.
value( QStringLiteral(
"cache/directory" ) ).toString();
741 if ( cacheDirectory.isEmpty() )
742 cacheDirectory = QStandardPaths::writableLocation( QStandardPaths::CacheLocation );
743 const qint64 cacheSize = settings.
value( QStringLiteral(
"cache/size" ), 256 * 1024 * 1024 ).toLongLong();
749 if ( cache() != newcache )
750 setCache( newcache );
752 if (
this != sMainNAM )
754 static_cast<QgsNetworkCookieJar *
>( cookieJar() )->setAllCookies(
static_cast<QgsNetworkCookieJar *
>( sMainNAM->cookieJar() )->allCookies() );
758void QgsNetworkAccessManager::syncCookies(
const QList<QNetworkCookie> &cookies )
760 if ( sender() !=
this )
762 static_cast<QgsNetworkCookieJar *
>( cookieJar() )->setAllCookies( cookies );
763 if (
this == sMainNAM )
784 br.
get( request, forceRefresh, feedback );
792 br.
post( request, data, forceRefresh, feedback );
798 QString
id = QUuid::createUuid().toString();
799 sCustomPreprocessors.emplace_back( std::make_pair(
id, processor ) );
805 const size_t prevCount = sCustomPreprocessors.size();
806 sCustomPreprocessors.erase( std::remove_if( sCustomPreprocessors.begin(), sCustomPreprocessors.end(), [
id]( std::pair< QString, std::function<
void( QNetworkRequest * ) > > &a )
808 return a.first == id;
809 } ), sCustomPreprocessors.end() );
810 return prevCount != sCustomPreprocessors.size();
815 QString
id = QUuid::createUuid().toString();
816 sCustomReplyPreprocessors.emplace_back( std::make_pair(
id, processor ) );
822 const size_t prevCount = sCustomReplyPreprocessors.size();
823 sCustomReplyPreprocessors.erase( std::remove_if( sCustomReplyPreprocessors.begin(), sCustomReplyPreprocessors.end(), [
id]( std::pair< QString, std::function<
void(
const QNetworkRequest &, QNetworkReply * ) > > &a )
825 return a.first == id;
826 } ), sCustomReplyPreprocessors.end() );
827 return prevCount != sCustomReplyPreprocessors.size();
832 for (
const auto &preprocessor : sCustomPreprocessors )
834 preprocessor.second( req );
844 : mOperation( operation )
845 , mRequest( request )
846 , mOriginatingThreadId( QStringLiteral(
"0x%2" ).arg( reinterpret_cast<quintptr>( QThread::currentThread() ), 2 * QT_POINTER_SIZE, 16, QLatin1Char(
'0' ) ) )
847 , mRequestId( requestId )
848 , mContent( content )
849 , mInitiatorClass( request.attribute( static_cast< QNetworkRequest::Attribute >(
QgsNetworkRequestParameters::AttributeInitiatorClass ) ).toString() )
850 , mInitiatorRequestId( request.attribute( static_cast< QNetworkRequest::Attribute >(
QgsNetworkRequestParameters::AttributeInitiatorRequestId ) ) )
862 QgsDebugMsg( QStringLiteral(
"SSL errors occurred accessing URL:\n%1" ).arg( reply->request().url().toString() ) );
872 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() ) );
878 QgsDebugMsg( QStringLiteral(
"Network authentication required external browser to open URL %1, but no handler was in place" ).arg( url.toString() ) );
883 QgsDebugMsg( QStringLiteral(
"Network authentication required external browser closed, but no handler was in place" ) );
887#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(), 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.
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 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.
bool setValue(T value, const QString &dynamicKeyPart=QString()) const
Set settings value.
T value(const QString &dynamicKeyPart=QString()) 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)