Skip to content

Commit

Permalink
fix(qgshttpheaders): add backward compatibility in setFromUrlQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitdm-oslandia authored and nyalldawson committed Aug 21, 2024
1 parent 4e88a25 commit b40920d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/core/network/qgshttpheaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ void QgsHttpHeaders::setFromUrlQuery( const QUrlQuery &uri )
QString name = key.right( key.size() - QgsHttpHeaders::PARAM_PREFIX.size() );
mHeaders[sanitizeKey( name )] = item.second;
}
else if ( key == QgsHttpHeaders::KEY_REFERER ) // backward comptibility
{
mHeaders[QgsHttpHeaders::KEY_REFERER] = item.second;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsdatasourceuri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ void QgsDataSourceUri::setEncodedUri( const QByteArray &uri )
const auto constQueryItems = query.queryItems();
for ( const QPair<QString, QString> &item : constQueryItems )
{
if ( !item.first.startsWith( QgsHttpHeaders::PARAM_PREFIX ) )
if ( !item.first.startsWith( QgsHttpHeaders::PARAM_PREFIX ) && item.first != QgsHttpHeaders::KEY_REFERER )
{
if ( item.first == QLatin1String( "username" ) )
mUsername = query.queryItemValue( QStringLiteral( "username" ), QUrl::ComponentFormattingOption::FullyDecoded );
Expand Down
32 changes: 32 additions & 0 deletions tests/src/core/testqgshttpheaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class TestQgsHttpheaders: public QObject

void setFromSettingsGoodKey();
void setFromSettingsBadKey();
void setFromUrlQuery();
void updateSettings();

void createQgsOwsConnection();
Expand Down Expand Up @@ -179,6 +180,37 @@ void TestQgsHttpheaders::updateNetworkRequest()
}


void TestQgsHttpheaders::setFromUrlQuery()
{
{
// with only new http-header:referer
QUrlQuery url( "https://www.ogc.org/?p1=v1&http-header:other_http_header=value&http-header:referer=http://test.new.com" );
QgsHttpHeaders h;
h.setFromUrlQuery( url );
QCOMPARE( h[QgsHttpHeaders::KEY_REFERER ].toString(), QStringLiteral( "http://test.new.com" ) );
QCOMPARE( h[ "other_http_header" ].toString(), QStringLiteral( "value" ) );
}

{
// with both new http-header:referer and old referer
QUrlQuery url( "https://www.ogc.org/?p1=v1&referer=http://test.old.com&http-header:other_http_header=value&http-header:referer=http://test.new.com" );
QgsHttpHeaders h;
h.setFromUrlQuery( url );
QCOMPARE( h[QgsHttpHeaders::KEY_REFERER ].toString(), QStringLiteral( "http://test.new.com" ) );
QCOMPARE( h[ "other_http_header" ].toString(), QStringLiteral( "value" ) );
}

{
// with only old referer
QUrlQuery url( "https://www.ogc.org/?p1=v1&referer=http://test.old.com&http-header:other_http_header=value" );
QgsHttpHeaders h;
h.setFromUrlQuery( url );
QCOMPARE( h[QgsHttpHeaders::KEY_REFERER ].toString(), QStringLiteral( "http://test.old.com" ) );
QCOMPARE( h[ "other_http_header" ].toString(), QStringLiteral( "value" ) );
}
}


void TestQgsHttpheaders::updateSetUrlQuery()
{
QUrlQuery url( "http://ogc.org" );
Expand Down

0 comments on commit b40920d

Please sign in to comment.