Skip to content

Commit

Permalink
Merge pull request #59710 from nyalldawson/backport_59619
Browse files Browse the repository at this point in the history
Fix case-sensitivity of http header checks (LTR)
  • Loading branch information
alexbruy authored Dec 3, 2024
2 parents 8a040d1 + 8b1aa55 commit 3f5cf8c
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 3f5cf8c

Please sign in to comment.