Skip to content
Snippets Groups Projects
Commit 54c806f8 authored by Jørn Åne's avatar Jørn Åne
Browse files

Simplify Module.php static asset cache configuration

parent 96558bb5
No related branches found
No related tags found
No related merge requests found
......@@ -862,37 +862,19 @@ $config = [
'production' => true,
/*
* Set this option to adjust basic caching directives sent by module.php.
*
* Defaults to ['public' => true, 'max_age' => 86400]
*/
// 'module.php.cache' => ['public' => true, 'max_age' => 86400],
/*
* Set this option to adjust expiration timestamp sent by module.php.
* The value (in seconds) is added to current time.
* If set to null, the Expiration header is not sent at all.
*
* Defaults to 10 * 60 (ten minutes).
*/
// 'module.php.expires' => 10 * 60,
/*
* Set this option to make module.php automatically send Etag.
*
* Defaults to false.
*/
// 'module.php.etag' => false,
/*
* Set this option to adjust more caching directives sent by module.php,
* for example must-revalidate. The option takes an array
* where keys are the caching directive names and values are the corresponding values.
*
* Defaults to [] (empty array).
*/
// 'module.php.directives' => [],
* SimpleSAMLphp modules can host static resources which are served through PHP.
* The serving of the resources can be configured through these settings.
*/
'assets' => [
'caching' => [
/**
* These settings adjust the caching headers that are sent
* when serving static resources.
*/
'max_age' => 86400,
'etag' => false,
],
],
/*********************
| DISCOVERY SERVICE |
......
......@@ -264,20 +264,13 @@ class Module
}
}
$assetConfig = $config->getArray('assets', ['caching' => ['max_age' => 86400, 'etag' => false]]);
$response = new BinaryFileResponse($path);
$cacheSettings = $config->getArray('module.php.cache', ['public' => true, 'max_age' => 86400]);
$response->setCache($cacheSettings);
$cacheExpiration = $config->getValue('module.php.expires', 10 * 60);
$expires = $cacheExpiration === null ? null : new \DateTime('@' . (time() + $cacheExpiration));
$response->setExpires($expires);
$cacheEtag = $config->getBoolean('module.php.etag', false);
if ($cacheEtag) {
$response->setCache(['public' => true, 'max_age' => $assetConfig['caching']['max_age']]);
$response->setAutoLastModified();
if ($assetConfig['caching']['etag']) {
$response->setAutoEtag();
}
$cacheDirectives = $config->getArray('module.php.directives', []);
foreach ($cacheDirectives as $directiveName => $directiveValue) {
$response->headers->addCacheControlDirective($directiveName, $directiveValue);
}
$response->isNotModified($request);
$response->headers->set('Content-Type', $contentType);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment