Skip to content
Permalink
Browse files

Use direct connection for NAM auth connections

  • Loading branch information
m-kuhn committed May 24, 2018
1 parent b756a02 commit 620d4d7abbfaf9f0cc11f06402acc5eb7a51dd58
@@ -32,7 +32,7 @@ that the fallback proxy should not be used for, then no proxy will be used.
#include "qgsnetworkaccessmanager.h"
%End
public:
static QgsNetworkAccessManager *instance();
static QgsNetworkAccessManager *instance( Qt::ConnectionType connectionType = Qt::DirectConnection );

QgsNetworkAccessManager( QObject *parent = 0 );

@@ -76,7 +76,7 @@ Gets name for QNetworkRequest.CacheLoadControl
Gets QNetworkRequest.CacheLoadControl from name
%End

void setupDefaultProxyAndCache();
void setupDefaultProxyAndCache( Qt::ConnectionType connectionType = Qt::BlockingQueuedConnection );
%Docstring
Setup the NAM according to the user's settings
%End
@@ -102,7 +102,7 @@ class QgsNetworkProxyFactory : public QNetworkProxyFactory
//
// Static calls to enforce singleton behavior
//
QgsNetworkAccessManager *QgsNetworkAccessManager::instance()
QgsNetworkAccessManager *QgsNetworkAccessManager::instance( Qt::ConnectionType connectionType )
{
static QThreadStorage<QgsNetworkAccessManager> sInstances;
QgsNetworkAccessManager *nam = &sInstances.localData();
@@ -111,7 +111,7 @@ QgsNetworkAccessManager *QgsNetworkAccessManager::instance()
sMainNAM = nam;

if ( !nam->mInitialized )
nam->setupDefaultProxyAndCache();
nam->setupDefaultProxyAndCache( connectionType );

return nam;
}
@@ -281,7 +281,7 @@ QNetworkRequest::CacheLoadControl QgsNetworkAccessManager::cacheLoadControlFromN
return QNetworkRequest::PreferNetwork;
}

void QgsNetworkAccessManager::setupDefaultProxyAndCache()
void QgsNetworkAccessManager::setupDefaultProxyAndCache( Qt::ConnectionType connectionType )
{
mInitialized = true;
mUseSystemProxy = false;
@@ -292,19 +292,19 @@ void QgsNetworkAccessManager::setupDefaultProxyAndCache()
{
connect( this, &QNetworkAccessManager::authenticationRequired,
sMainNAM, &QNetworkAccessManager::authenticationRequired,
Qt::BlockingQueuedConnection );
connectionType );

connect( this, &QNetworkAccessManager::proxyAuthenticationRequired,
sMainNAM, &QNetworkAccessManager::proxyAuthenticationRequired,
Qt::BlockingQueuedConnection );
connectionType );

connect( this, &QgsNetworkAccessManager::requestTimedOut,
sMainNAM, &QgsNetworkAccessManager::requestTimedOut );

#ifndef QT_NO_SSL
connect( this, &QNetworkAccessManager::sslErrors,
sMainNAM, &QNetworkAccessManager::sslErrors,
Qt::BlockingQueuedConnection );
connectionType );
#endif
}

@@ -51,7 +51,7 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
public:
//! returns a pointer to the single instance
// and creates that instance on the first call.
static QgsNetworkAccessManager *instance();
static QgsNetworkAccessManager *instance( Qt::ConnectionType connectionType = Qt::DirectConnection );

QgsNetworkAccessManager( QObject *parent = nullptr );

@@ -80,7 +80,7 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
static QNetworkRequest::CacheLoadControl cacheLoadControlFromName( const QString &name );

//! Setup the NAM according to the user's settings
void setupDefaultProxyAndCache();
void setupDefaultProxyAndCache( Qt::ConnectionType connectionType = Qt::BlockingQueuedConnection );

//! Returns whether the system proxy should be used
bool useSystemProxy() const { return mUseSystemProxy; }
@@ -133,6 +133,9 @@ bool QgsWfsRequest::sendGET( const QUrl &url, bool synchronous, bool forceRefres
QMutex mutex;
std::function<bool()> downloaderFunction = [ this, request, synchronous, &waitCondition ]()
{
if ( QThread::currentThread() != QgsApplication::instance()->thread() )
QgsNetworkAccessManager::instance( Qt::DirectConnection );

bool success = true;
mReply = QgsNetworkAccessManager::instance()->get( request );

0 comments on commit 620d4d7

Please sign in to comment.
You can’t perform that action at this time.