Skip to content

Commit

Permalink
fix(core): extract httpheaders when creating QgsDataSourceUri from st…
Browse files Browse the repository at this point in the history
…ring
  • Loading branch information
benoitdm-oslandia authored and github-actions[bot] committed Jan 11, 2023
1 parent b378df3 commit 23dd1ab
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions python/core/auto_generated/network/qgshttpheaders.sip.in
Expand Up @@ -149,6 +149,14 @@ Returns a cleansed ``key``
QVariant &operator[]( const QString &key );


void insert( const QString &key, const QVariant &value );
%Docstring
insert a ``key`` with the specific ``value``

:param key: a key to add
:param value: a value to add for the key
%End

QList<QString> keys() const;
%Docstring

Expand Down
12 changes: 12 additions & 0 deletions src/core/network/qgshttpheaders.cpp
Expand Up @@ -272,3 +272,15 @@ QList<QString> QgsHttpHeaders::keys() const
{
return mHeaders.keys();
}


void QgsHttpHeaders::insert( const QString &key, const QVariant &val )
{
QString k2 = key;

if ( k2.startsWith( QgsHttpHeaders::PARAM_PREFIX ) )
{
k2 = k2.right( k2.length() - QgsHttpHeaders::PARAM_PREFIX.length() );
}
mHeaders.insert( k2, val );
}
7 changes: 7 additions & 0 deletions src/core/network/qgshttpheaders.h
Expand Up @@ -174,6 +174,13 @@ class CORE_EXPORT QgsHttpHeaders

QgsHttpHeaders &operator = ( const QMap<QString, QVariant> &headers ) SIP_SKIP;

/**
* \brief insert a \a key with the specific \a value
* \param key a key to add
* \param value a value to add for the key
*/
void insert( const QString &key, const QVariant &value );

/**
* \return the list of all http header keys
*/
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsdatasourceuri.cpp
Expand Up @@ -209,6 +209,10 @@ QgsDataSourceUri::QgsDataSourceUri( const QString &u )
{
QgsDebugMsg( QStringLiteral( "gsslib ignored" ) );
}
else if ( pname.startsWith( QgsHttpHeaders::PARAM_PREFIX ) )
{
mHttpHeaders.insert( pname, pval );
}
else
{
QgsDebugMsgLevel( "parameter \"" + pname + "\":\"" + pval + "\" added", 4 );
Expand Down
8 changes: 8 additions & 0 deletions tests/src/core/testqgshttpheaders.cpp
Expand Up @@ -148,6 +148,14 @@ void TestQgsHttpheaders::createQgsOwsConnection()
QgsDataSourceUri uri( QString( "https://www.ogc.org/?p1=v1" ) );
QgsDataSourceUri uri2 = ows.addWmsWcsConnectionSettings( uri, "service", "name" );
QCOMPARE( uri2.encodedUri(), "https://www.ogc.org/?p1=v1&http-header:other_http_header=value&http-header:referer=http://test.com" );

// check space separated string
QCOMPARE( uri2.uri(), " https://www.ogc.org/?p1='v1' http-header:other_http_header='value' http-header:referer='http://test.com' referer='http://test.com'" );
// build new QgsDataSourceUri according to space separated string
QgsDataSourceUri uri3( uri2.uri() );
QCOMPARE( uri3.httpHeader( QgsHttpHeaders::KEY_REFERER ), "http://test.com" );
QCOMPARE( uri3.httpHeader( "other_http_header" ), "value" );
QCOMPARE( uri3.encodedUri(), "https://www.ogc.org/?p1=v1&referer=http://test.com&http-header:other_http_header=value&http-header:referer=http://test.com" );
}


Expand Down

0 comments on commit 23dd1ab

Please sign in to comment.