From 589568759b074dd0478615f785a2297a1800d79f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 12 Jan 2010 15:20:28 +0100 Subject: Fix an issue with HTTP headers like "private, max-age=300". The parsing would ignore the fact that "private" ended at the comma and would instead try to get the continuation as the value. We have to check if equal < comma and it's not -1. Using unsigned comparisons does both things at once for us. Task-number: QTBUG-7060 Reviewed-by: Peter Hartmann --- src/network/access/qnetworkaccesshttpbackend.cpp | 2 +- .../tests/httpcachetest_cachecontrol200.cgi | 9 +++++++++ tests/auto/qabstractnetworkcache/tst_qabstractnetworkcache.cpp | 8 +++++++- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tests/auto/qabstractnetworkcache/tests/httpcachetest_cachecontrol200.cgi diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp index a639e0d..58123b2 100644 --- a/src/network/access/qnetworkaccesshttpbackend.cpp +++ b/src/network/access/qnetworkaccesshttpbackend.cpp @@ -144,7 +144,7 @@ static QHash parseHttpOptionHeader(const QByteArray &hea QByteArray key = QByteArray(header.constData() + pos, end - pos).trimmed().toLower(); pos = end + 1; - if (equal != -1) { + if (uint(equal) < uint(comma)) { // case: token "=" (token | quoted-string) // skip spaces pos = nextNonWhitespace(header, pos); diff --git a/tests/auto/qabstractnetworkcache/tests/httpcachetest_cachecontrol200.cgi b/tests/auto/qabstractnetworkcache/tests/httpcachetest_cachecontrol200.cgi new file mode 100644 index 0000000..e44d5ed --- /dev/null +++ b/tests/auto/qabstractnetworkcache/tests/httpcachetest_cachecontrol200.cgi @@ -0,0 +1,9 @@ +#!/bin/bash +cc=`echo "${QUERY_STRING}" | sed -e s/%20/\ /g` +echo "Status: 200" +echo "Cache-Control: $cc" +echo "Last-Modified: Sat, 31 Oct 1981 06:00:00 GMT" +echo "Content-type: text/html"; +echo "X-Script: $0" +echo "" +echo "Hello World!" diff --git a/tests/auto/qabstractnetworkcache/tst_qabstractnetworkcache.cpp b/tests/auto/qabstractnetworkcache/tst_qabstractnetworkcache.cpp index ac73f08..04bd432 100644 --- a/tests/auto/qabstractnetworkcache/tst_qabstractnetworkcache.cpp +++ b/tests/auto/qabstractnetworkcache/tst_qabstractnetworkcache.cpp @@ -205,6 +205,11 @@ void tst_QAbstractNetworkCache::cacheControl_data() QTest::newRow("304-2") << QNetworkRequest::PreferNetwork << "httpcachetest_cachecontrol.cgi?max-age=1000, must-revalidate" << true; QTest::newRow("304-3") << QNetworkRequest::AlwaysCache << "httpcachetest_cachecontrol.cgi?max-age=1000, must-revalidate" << AlwaysTrue; QTest::newRow("304-4") << QNetworkRequest::PreferCache << "httpcachetest_cachecontrol.cgi?max-age=1000, must-revalidate" << true; + + // see QTBUG-7060 + //QTest::newRow("nokia-boston") << QNetworkRequest::PreferNetwork << "http://waplabdc.nokia-boston.com/browser/users/venkat/cache/Cache_directives/private_1b.asp" << true; + QTest::newRow("304-2b") << QNetworkRequest::PreferNetwork << "httpcachetest_cachecontrol200.cgi?private, max-age=1000" << true; + QTest::newRow("304-4b") << QNetworkRequest::PreferCache << "httpcachetest_cachecontrol200.cgi?private, max-age=1000" << true; } void tst_QAbstractNetworkCache::cacheControl() @@ -223,7 +228,8 @@ void tst_QAbstractNetworkCache::check() manager.setCache(diskCache); QCOMPARE(diskCache->gotData, false); - QNetworkRequest request(QUrl(TESTFILE + url)); + QUrl realUrl = url.contains("://") ? url : TESTFILE + url; + QNetworkRequest request(realUrl); // prime the cache QNetworkReply *reply = manager.get(request); -- cgit v0.12