diff options
-rw-r--r-- | src/network/access/qnetworkreplyhttpimpl.cpp | 24 | ||||
-rw-r--r-- | tests/auto/network/access/qabstractnetworkcache/tst_qabstractnetworkcache.cpp | 4 |
2 files changed, 13 insertions, 15 deletions
diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 920dfdbb38..367c92a460 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -560,23 +560,21 @@ bool QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed(QHttpNetworkRequest &h int resident_time = now - response_time; int current_age = corrected_initial_age + resident_time; + int freshness_lifetime = 0; + // RFC 2616 13.2.4 Expiration Calculations - if (!expirationDate.isValid()) { - if (lastModified.isValid()) { - int diff = currentDateTime.secsTo(lastModified); - expirationDate = lastModified.addSecs(diff / 10); - if (httpRequest.headerField("Warning").isEmpty()) { - QDateTime dt; - dt.setTime_t(current_age); - if (dt.daysTo(currentDateTime) > 1) - httpRequest.setHeaderField("Warning", "113"); - } + if (lastModified.isValid() && dateHeader.isValid()) { + int diff = lastModified.secsTo(dateHeader); + freshness_lifetime = diff / 10; + if (httpRequest.headerField("Warning").isEmpty()) { + QDateTime dt = currentDateTime.addSecs(current_age); + if (currentDateTime.daysTo(dt) > 1) + httpRequest.setHeaderField("Warning", "113"); } } - // the cache-saving code below sets the expirationDate with date+max_age - // if "max-age" is present, or to Expires otherwise - int freshness_lifetime = dateHeader.secsTo(expirationDate); + // the cache-saving code below sets the freshness_lifetime with (dateHeader - last_modified) / 10 + // if "last-modified" is present, or to Expires otherwise response_is_fresh = (freshness_lifetime > current_age); } else { // expiration date was calculated earlier (e.g. when storing object to the cache) diff --git a/tests/auto/network/access/qabstractnetworkcache/tst_qabstractnetworkcache.cpp b/tests/auto/network/access/qabstractnetworkcache/tst_qabstractnetworkcache.cpp index da86a2d14d..aca48567eb 100644 --- a/tests/auto/network/access/qabstractnetworkcache/tst_qabstractnetworkcache.cpp +++ b/tests/auto/network/access/qabstractnetworkcache/tst_qabstractnetworkcache.cpp @@ -203,9 +203,9 @@ void tst_QAbstractNetworkCache::lastModified_data() QTest::newRow("304-3") << QNetworkRequest::PreferCache << "httpcachetest_lastModified304.cgi" << true; QTest::newRow("200-0") << QNetworkRequest::AlwaysNetwork << "httpcachetest_lastModified200.cgi" << AlwaysFalse; - QTest::newRow("200-1") << QNetworkRequest::PreferNetwork << "httpcachetest_lastModified200.cgi" << false; + QTest::newRow("200-1") << QNetworkRequest::PreferNetwork << "httpcachetest_lastModified200.cgi" << true; QTest::newRow("200-2") << QNetworkRequest::AlwaysCache << "httpcachetest_lastModified200.cgi" << AlwaysTrue; - QTest::newRow("200-3") << QNetworkRequest::PreferCache << "httpcachetest_lastModified200.cgi" << false; + QTest::newRow("200-3") << QNetworkRequest::PreferCache << "httpcachetest_lastModified200.cgi" << true; } void tst_QAbstractNetworkCache::lastModified() |