Skip to content

Commit

Permalink
Fix case-sensitivity of http header checks
Browse files Browse the repository at this point in the history
Since qt 6.8 header keys are forced to lowercase, so we need to
adapt all checks accordingly

(cherry picked from commit 682aae0)
  • Loading branch information
nyalldawson committed Dec 2, 2024
1 parent cc42b13 commit 8b1aa55
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/providers/wfs/qgsbasenetworkrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,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 @@ -439,7 +439,15 @@ void TestQgsNetworkAccessManager::fetchEncodedContent()
{
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 @@ -524,7 +532,15 @@ void TestQgsNetworkAccessManager::fetchPost()
{
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 @@ -614,7 +630,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
9 changes: 5 additions & 4 deletions tests/src/python/test_qgsblockingnetworkrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ def testGet(self):
reply = request.reply()
self.assertEqual(reply.error(), QNetworkReply.NoError)
self.assertEqual(reply.content(), '<html></html>\n')
self.assertEqual(reply.rawHeaderList(), [b'Server',
b'Date',
b'Content-type',
b'Content-Length'])
# newer qt versions FORCE lowercase header keys, older ones didn't
self.assertEqual(
[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'), '')
self.assertEqual(reply.attribute(QNetworkRequest.HttpStatusCodeAttribute), 200)
Expand Down

0 comments on commit 8b1aa55

Please sign in to comment.