Skip to content

Commit

Permalink
Use direct connection for NAM auth connections
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jun 14, 2018
1 parent b756a02 commit 620d4d7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions python/core/auto_generated/qgsnetworkaccessmanager.sip.in
Expand Up @@ -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 );

Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/core/qgsnetworkaccessmanager.cpp
Expand Up @@ -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();
Expand All @@ -111,7 +111,7 @@ QgsNetworkAccessManager *QgsNetworkAccessManager::instance()
sMainNAM = nam;

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

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

void QgsNetworkAccessManager::setupDefaultProxyAndCache()
void QgsNetworkAccessManager::setupDefaultProxyAndCache( Qt::ConnectionType connectionType )
{
mInitialized = true;
mUseSystemProxy = false;
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsnetworkaccessmanager.h
Expand Up @@ -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 );

Expand Down Expand Up @@ -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; }
Expand Down
3 changes: 3 additions & 0 deletions src/providers/wfs/qgswfsrequest.cpp
Expand Up @@ -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 );

Expand Down

0 comments on commit 620d4d7

Please sign in to comment.