diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 07f183bc..2b7ae1da 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -16,6 +16,7 @@ use FOS\HttpCache\SymfonyCache\PurgeListener; use FOS\HttpCache\SymfonyCache\PurgeTagsListener; use FOS\HttpCache\TagHeaderFormatter\TagHeaderFormatter; +use FOS\HttpCacheBundle\EventListener\CacheControlListener; use JeanBeru\HttpCacheCloudFront\Proxy\CloudFront; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\NodeBuilder; @@ -278,7 +279,7 @@ private function addCacheControlSection(ArrayNodeDefinition $rootNode): void ->end() ->end() ->scalarNode('ttl_header') - ->defaultValue('X-Reverse-Proxy-TTL') + ->defaultValue(CacheControlListener::DEFAULT_TTL_HEADER_NAME) ->info('Specify the header name to use with the cache_control.reverse_proxy_ttl setting') ->end() ->arrayNode('rules') diff --git a/src/DependencyInjection/FOSHttpCacheExtension.php b/src/DependencyInjection/FOSHttpCacheExtension.php index 428054f5..d7236752 100644 --- a/src/DependencyInjection/FOSHttpCacheExtension.php +++ b/src/DependencyInjection/FOSHttpCacheExtension.php @@ -17,6 +17,7 @@ use FOS\HttpCache\SymfonyCache\KernelDispatcher; use FOS\HttpCache\TagHeaderFormatter\MaxHeaderValueLengthFormatter; use FOS\HttpCacheBundle\DependencyInjection\Compiler\HashGeneratorPass; +use FOS\HttpCacheBundle\EventListener\CacheControlListener; use FOS\HttpCacheBundle\Http\ResponseMatcher\ExpressionResponseMatcher; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; @@ -48,7 +49,7 @@ public function load(array $configs, ContainerBuilder $container): void if ($config['debug']['enabled'] || (!empty($config['cache_control']))) { $debugHeader = $config['debug']['enabled'] ? $config['debug']['header'] : false; - $ttlHeader = $config['cache_control']['ttl_header'] ?? null; + $ttlHeader = $config['cache_control']['ttl_header'] ?? CacheControlListener::DEFAULT_TTL_HEADER_NAME; $container->setParameter('fos_http_cache.debug_header', $debugHeader); $container->setParameter('fos_http_cache.ttl_header', $ttlHeader); $loader->load('cache_control_listener.xml'); diff --git a/src/EventListener/CacheControlListener.php b/src/EventListener/CacheControlListener.php index d9bfbdee..5ecd47db 100644 --- a/src/EventListener/CacheControlListener.php +++ b/src/EventListener/CacheControlListener.php @@ -28,6 +28,8 @@ */ final class CacheControlListener implements EventSubscriberInterface { + public const DEFAULT_TTL_HEADER_NAME = 'X-Reverse-Proxy-TTL'; + /** * Whether to skip this response and not set any cache headers. */ @@ -56,7 +58,7 @@ public function __construct( * @var string|false Name of the header or false to add no header */ private readonly string|false $debugHeader = false, - private readonly string $ttlHeader = 'X-Reverse-Proxy-TTL', + private readonly string $ttlHeader = self::DEFAULT_TTL_HEADER_NAME, ) { }