Fix autotest failures in QAbstractNetworkCache
The cache expiration calculation was previously removed to avoid calculating it every time an object is fetched from the cache. This is because the expiration date is calculated from max-age or expires headers when the object is added to the cache. However this broke the case where the server only provides a last-modified header. In this case, the expiration date needs to be checked at fetch time in order to add the warning if the object is >24h old. Change-Id: Iad381da0f91c27ac603abbaa94f268700ad2297f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
17412400dc
commit
3c0fdefc31
@ -513,7 +513,8 @@ bool QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed(QHttpNetworkRequest &h
|
||||
QDateTime currentDateTime = QDateTime::currentDateTime();
|
||||
QDateTime expirationDate = metaData.expirationDate();
|
||||
|
||||
#if 0
|
||||
bool response_is_fresh;
|
||||
if (!expirationDate.isValid()) {
|
||||
/*
|
||||
* age_value
|
||||
* is the value of Age: header received by the cache with
|
||||
@ -572,10 +573,11 @@ bool QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed(QHttpNetworkRequest &h
|
||||
// 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);
|
||||
bool response_is_fresh = (freshness_lifetime > current_age);
|
||||
#else
|
||||
bool response_is_fresh = currentDateTime.secsTo(expirationDate) >= 0;
|
||||
#endif
|
||||
response_is_fresh = (freshness_lifetime > current_age);
|
||||
} else {
|
||||
// expiration date was calculated earlier (e.g. when storing object to the cache)
|
||||
response_is_fresh = currentDateTime.secsTo(expirationDate) >= 0;
|
||||
}
|
||||
|
||||
if (!response_is_fresh)
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user