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
  • Loading branch information
nyalldawson committed Nov 27, 2024
1 parent 0dbf6e7 commit c4d78cd
Show file tree
Hide file tree
Showing 3 changed files with 34 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 @@ -513,7 +513,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
10 changes: 6 additions & 4 deletions tests/src/python/test_qgsblockingnetworkrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ def testGet(self):
reply = request.reply()
self.assertEqual(reply.error(), QNetworkReply.NetworkError.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.Attribute.HttpStatusCodeAttribute), 200)
Expand Down

0 comments on commit c4d78cd

Please sign in to comment.