Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix case-sensitivity of http header checks #59619

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/providers/wfs/qgsbasenetworkrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ QStringList QgsBaseNetworkRequest::sendOPTIONS( const QUrl &url )

for ( const auto &headerKeyValue : mResponseHeaders )
{
if ( headerKeyValue.first == QByteArray( "Allow" ) )
if ( headerKeyValue.first.compare( QByteArray( "Allow" ), Qt::CaseInsensitive ) == 0 )
{
allowValue = headerKeyValue.second;
break;
Expand Down
30 changes: 27 additions & 3 deletions tests/src/core/testqgsnetworkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,15 @@ void TestQgsNetworkAccessManager::fetchEncodedContent()
connect( QgsNetworkAccessManager::instance(), qOverload<QgsNetworkReplyContent>( &QgsNetworkAccessManager::finished ), &context, [&]( const QgsNetworkReplyContent &reply ) {
QCOMPARE( reply.error(), QNetworkReply::NoError );
QCOMPARE( reply.requestId(), requestId );
QVERIFY( reply.rawHeaderList().contains( "Content-Length" ) );

// newer qt versions force headers to lower case, older ones didn't
QStringList lowerCaseRawHeaders;
for ( const QByteArray &header : reply.rawHeaderList() )
{
lowerCaseRawHeaders.append( header.toLower() );
}

QVERIFY( lowerCaseRawHeaders.contains( "content-length" ) );
QCOMPARE( reply.request().url(), u );
loaded = true;
} );
Expand Down Expand Up @@ -502,7 +510,15 @@ void TestQgsNetworkAccessManager::fetchPost()
connect( QgsNetworkAccessManager::instance(), qOverload<QgsNetworkReplyContent>( &QgsNetworkAccessManager::finished ), &context, [&]( const QgsNetworkReplyContent &reply ) {
QCOMPARE( reply.error(), QNetworkReply::NoError );
QCOMPARE( reply.requestId(), requestId );
QVERIFY( reply.rawHeaderList().contains( "Content-Type" ) );

// newer qt versions force headers to lower case, older ones didn't
QStringList lowerCaseRawHeaders;
for ( const QByteArray &header : reply.rawHeaderList() )
{
lowerCaseRawHeaders.append( header.toLower() );
}

QVERIFY( lowerCaseRawHeaders.contains( "content-type" ) );
QCOMPARE( reply.request().url(), u );
loaded = true;
} );
Expand Down Expand Up @@ -591,7 +607,15 @@ void TestQgsNetworkAccessManager::fetchPostMultiPart()
el.exec();

QCOMPARE( reply->error(), QNetworkReply::NoError );
QVERIFY( reply->rawHeaderList().contains( "Content-Type" ) );

// newer qt versions force headers to lower case, older ones didn't
QStringList lowerCaseRawHeaders;
for ( const QByteArray &header : reply->rawHeaderList() )
{
lowerCaseRawHeaders.append( header.toLower() );
}
QVERIFY( lowerCaseRawHeaders.contains( "content-type" ) );

QCOMPARE( reply->request().url(), u );
}

Expand Down
5 changes: 3 additions & 2 deletions tests/src/python/test_qgsblockingnetworkrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ def testGet(self):
reply = request.reply()
self.assertEqual(reply.error(), QNetworkReply.NetworkError.NoError)
self.assertEqual(reply.content(), "<html></html>\n")
# newer qt versions FORCE lowercase header keys, older ones didn't
self.assertEqual(
reply.rawHeaderList(),
[b"Server", b"Date", b"Content-type", b"Content-Length"],
[h.data().decode().lower() for h in reply.rawHeaderList()],
["server", "date", "content-type", "content-length"],
)
self.assertEqual(reply.rawHeader(b"Content-type"), "text/html")
self.assertEqual(reply.rawHeader(b"xxxxxxxxx"), "")
Expand Down
Loading