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 = [ ...@@ -862,37 +862,19 @@ $config = [
'production' => true, 'production' => true,
/* /*
* Set this option to adjust basic caching directives sent by module.php. * SimpleSAMLphp modules can host static resources which are served through PHP.
* * The serving of the resources can be configured through these settings.
* Defaults to ['public' => true, 'max_age' => 86400] */
*/ 'assets' => [
// 'module.php.cache' => ['public' => true, 'max_age' => 86400], 'caching' => [
/**
/* * These settings adjust the caching headers that are sent
* Set this option to adjust expiration timestamp sent by module.php. * when serving static resources.
* The value (in seconds) is added to current time. */
* If set to null, the Expiration header is not sent at all. 'max_age' => 86400,
* 'etag' => false,
* 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' => [],
/********************* /*********************
| DISCOVERY SERVICE | | DISCOVERY SERVICE |
......
...@@ -264,20 +264,13 @@ class Module ...@@ -264,20 +264,13 @@ class Module
} }
} }
$assetConfig = $config->getArray('assets', ['caching' => ['max_age' => 86400, 'etag' => false]]);
$response = new BinaryFileResponse($path); $response = new BinaryFileResponse($path);
$cacheSettings = $config->getArray('module.php.cache', ['public' => true, 'max_age' => 86400]); $response->setCache(['public' => true, 'max_age' => $assetConfig['caching']['max_age']]);
$response->setCache($cacheSettings); $response->setAutoLastModified();
$cacheExpiration = $config->getValue('module.php.expires', 10 * 60); if ($assetConfig['caching']['etag']) {
$expires = $cacheExpiration === null ? null : new \DateTime('@' . (time() + $cacheExpiration));
$response->setExpires($expires);
$cacheEtag = $config->getBoolean('module.php.etag', false);
if ($cacheEtag) {
$response->setAutoEtag(); $response->setAutoEtag();
} }
$cacheDirectives = $config->getArray('module.php.directives', []);
foreach ($cacheDirectives as $directiveName => $directiveValue) {
$response->headers->addCacheControlDirective($directiveName, $directiveValue);
}
$response->isNotModified($request); $response->isNotModified($request);
$response->headers->set('Content-Type', $contentType); $response->headers->set('Content-Type', $contentType);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE); $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