StaticController: Set a maximum age and honor no-cache for gravatar requests
refs #2917
This commit is contained in:
parent
b7639651e8
commit
7e358f3619
|
@ -31,19 +31,22 @@ class StaticController extends Controller
|
||||||
public function gravatarAction()
|
public function gravatarAction()
|
||||||
{
|
{
|
||||||
$response = $this->getResponse();
|
$response = $this->getResponse();
|
||||||
$response->setHeader('Pragma', 'cache')
|
$response->setHeader('Cache-Control', 'public, max-age=1814400, stale-while-revalidate=604800', true);
|
||||||
->setHeader('Cache-Control', 'public');
|
|
||||||
|
$noCache = $this->getRequest()->getHeader('Cache-Control') === 'no-cache'
|
||||||
|
|| $this->getRequest()->getHeader('Pragma') === 'no-cache';
|
||||||
|
|
||||||
$cache = FileCache::instance();
|
$cache = FileCache::instance();
|
||||||
$filename = md5(strtolower(trim($this->getParam('email'))));
|
$filename = md5(strtolower(trim($this->getParam('email'))));
|
||||||
$cacheFile = 'gravatar-' . $filename;
|
$cacheFile = 'gravatar-' . $filename;
|
||||||
if ($etag = $cache->etagMatchesCachedFile($cacheFile)) {
|
|
||||||
|
if (! $noCache && $cache->has($cacheFile, time() - 1814400)) {
|
||||||
|
if ($cache->etagMatchesCachedFile($cacheFile)) {
|
||||||
$response->setHttpResponseCode(304);
|
$response->setHttpResponseCode(304);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$response->setHeader('Content-Type', 'image/jpg');
|
$response->setHeader('Content-Type', 'image/jpg', true);
|
||||||
if ($cache->has($cacheFile)) {
|
|
||||||
$response->setHeader('ETag', sprintf('"%s"', $cache->etagForCachedFile($cacheFile)));
|
$response->setHeader('ETag', sprintf('"%s"', $cache->etagForCachedFile($cacheFile)));
|
||||||
$cache->send($cacheFile);
|
$cache->send($cacheFile);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue