diff --git a/config-templates/config.php b/config-templates/config.php index ea110c29aa75c6fa92c3fb9af4f406dae8e03d77..ae4f323256936df6e0ec4d6904eec65573ac8787 100644 --- a/config-templates/config.php +++ b/config-templates/config.php @@ -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 | diff --git a/lib/SimpleSAML/Module.php b/lib/SimpleSAML/Module.php index 25b3160eee0ea6f6d795b433e0c380ce9e3f45b4..84d2f4a63c6687c74c9a8916937919dbce730398 100644 --- a/lib/SimpleSAML/Module.php +++ b/lib/SimpleSAML/Module.php @@ -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);