mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-10 23:50:38 +08:00
HttpCache no longer returns 304 HTTP code when callbacks return null (#12099)
This commit is contained in:
@@ -26,6 +26,7 @@ Yii Framework 2 Change Log
|
||||
- Enh #11979: Added `yii\mutex\OracleMutex` which implements mutex "lock" mechanism via Oracle locks (zlakomanoff)
|
||||
- Enh #12082: Used `jQuery.on(` instead of event method to ensure forwards compatibility (newerton)
|
||||
- Enh #12028: Add -h|--help option to console command to display help information (pana1990)
|
||||
- Enh #12099: HttpCache no longer returns 304 HTTP code when callbacks return null (sergeymakinen)
|
||||
- Bug #12053: `./yii migrate/create` was generating wrong code when using `bigPrimaryKey` (VojtechH, samdark)
|
||||
- Bug #11907: Fixed `yii\helpers\Console::getScreenSize()` on Windows was giving out width and height swapped (Spell6inder, samdark, cebe)
|
||||
- Bug #11973: Fixed `yii\helpers\BaseHtml::getAttributeValue()` to work with `items[]` notation correctly (silverfire)
|
||||
|
||||
@@ -130,7 +130,9 @@ class HttpCache extends ActionFilter
|
||||
}
|
||||
if ($this->etagSeed !== null) {
|
||||
$seed = call_user_func($this->etagSeed, $action, $this->params);
|
||||
$etag = $this->generateEtag($seed);
|
||||
if ($seed !== null) {
|
||||
$etag = $this->generateEtag($seed);
|
||||
}
|
||||
}
|
||||
|
||||
$this->sendCacheControlHeader();
|
||||
@@ -140,20 +142,22 @@ class HttpCache extends ActionFilter
|
||||
$response->getHeaders()->set('Etag', $etag);
|
||||
}
|
||||
|
||||
if ($this->validateCache($lastModified, $etag)) {
|
||||
$cacheValid = $this->validateCache($lastModified, $etag);
|
||||
// https://tools.ietf.org/html/rfc7232#section-4.1
|
||||
if ($lastModified !== null && (!$cacheValid || ($cacheValid && $etag === null))) {
|
||||
$response->getHeaders()->set('Last-Modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');
|
||||
}
|
||||
if ($cacheValid) {
|
||||
$response->setStatusCode(304);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($lastModified !== null) {
|
||||
$response->getHeaders()->set('Last-Modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates if the HTTP cache contains valid content.
|
||||
* If both Last-Modified and ETag are null, returns false.
|
||||
* @param integer $lastModified the calculated Last-Modified value in terms of a UNIX timestamp.
|
||||
* If null, the Last-Modified header will not be validated.
|
||||
* @param string $etag the calculated ETag value. If null, the ETag header will not be validated.
|
||||
@@ -168,7 +172,7 @@ class HttpCache extends ActionFilter
|
||||
} elseif (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
|
||||
return $lastModified !== null && @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $lastModified;
|
||||
} else {
|
||||
return $etag === null && $lastModified === null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user