Skip to content

Commit

Permalink
Make QgsGdalUtils::setupProxy accept the URL for which the proxy shou…
Browse files Browse the repository at this point in the history
…ld be set up
  • Loading branch information
manisandro committed Jul 11, 2023
1 parent d31e537 commit 3a971e8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/core/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ QgsGdalProvider::QgsGdalProvider( const QString &uri, const ProviderOptions &opt
QgsGdalProviderBase::registerGdalDrivers();

#ifndef QT_NO_NETWORKPROXY
QgsGdalUtils::setupProxy();
QgsGdalUtils::setupProxy(uri);
#endif

std::unique_ptr< QgsScopedRuntimeProfile > profile;
Expand Down Expand Up @@ -3761,6 +3761,10 @@ QList<QgsProviderSublayerDetails> QgsGdalProviderMetadata::querySublayers( const
QString gdalUri = QgsGdalProvider::expandAuthConfig( uri );
QString npGdalUri = gdalUri;

#ifndef QT_NO_NETWORKPROXY
QgsGdalUtils::setupProxy(gdalUri);
#endif

QVariantMap uriParts = decodeUri( gdalUri );

// Try to open using VSIFileHandler
Expand Down
8 changes: 4 additions & 4 deletions src/core/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ QgsOgrProvider::QgsOgrProvider( QString const &uri, const ProviderOptions &optio
{
QgsApplication::registerOgrDrivers();

#ifndef QT_NO_NETWORKPROXY
QgsGdalUtils::setupProxy(uri);
#endif

QgsSettings settings;
// we always disable GDAL side shapefile encoding handling, and do it on the QGIS side.
// why? it's not the ideal choice, but...
Expand All @@ -407,10 +411,6 @@ QgsOgrProvider::QgsOgrProvider( QString const &uri, const ProviderOptions &optio
// a user does want/need to manually specify the encoding
CPLSetConfigOption( "SHAPE_ENCODING", "" );

#ifndef QT_NO_NETWORKPROXY
QgsGdalUtils::setupProxy();
#endif

// make connection to the data source

QgsDebugMsgLevel( "Data source uri is [" + uri + ']', 2 );
Expand Down
4 changes: 4 additions & 0 deletions src/core/providers/ogr/qgsogrprovidermetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,10 @@ QList<QgsProviderSublayerDetails> QgsOgrProviderMetadata::querySublayers( const
QStringList options { QStringLiteral( "@LIST_ALL_TABLES=YES" ) };
QVariantMap uriParts = decodeUri( uri );

#ifndef QT_NO_NETWORKPROXY
QgsGdalUtils::setupProxy(uri);
#endif

// Try to open using VSIFileHandler
QString vsiPrefix = QgsZipItem::vsiPrefix( uriParts.value( QStringLiteral( "path" ) ).toString() );
if ( !vsiPrefix.isEmpty() && uriParts.value( QStringLiteral( "vsiPrefix" ) ).toString().isEmpty() )
Expand Down
9 changes: 7 additions & 2 deletions src/core/qgsgdalutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,12 @@ void *QgsGdalUtils::rpcAwareCreateTransformer( GDALDatasetH hSrcDS, GDALDatasetH
}

#ifndef QT_NO_NETWORKPROXY
void QgsGdalUtils::setupProxy()
void QgsGdalUtils::setupProxy(const QString& uri)
{
QString url = uri;
if (uri.startsWith("/vsicurl/")) {
url = uri.mid(9);
}
// Check proxy configuration, they are application level but
// instead of adding an API and complex signal/slot connections
// given the limited cost of checking them on every provider instantiation
Expand All @@ -376,7 +380,8 @@ void QgsGdalUtils::setupProxy()
if ( settings.value( QStringLiteral( "proxy/proxyEnabled" ), false ).toBool() )
{
// Get the first configured proxy
QList<QNetworkProxy> proxies( QgsNetworkAccessManager::instance()->proxyFactory()->queryProxy( ) );
QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery( QNetworkProxyQuery( url ) );
}
if ( ! proxies.isEmpty() )
{
const QNetworkProxy proxy( proxies.first() );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsgdalutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class CORE_EXPORT QgsGdalUtils

#ifndef QT_NO_NETWORKPROXY
//! Sets the gdal proxy variables
static void setupProxy();
static void setupProxy(const QString& uri);
#endif

/**
Expand Down

0 comments on commit 3a971e8

Please sign in to comment.