Skip to content

Commit f793aec

Browse files
Add a flag to keep the custom ttl header (#504)
1 parent 9bdf22d commit f793aec

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/SymfonyCache/CustomTtlListener.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class CustomTtlListener implements EventSubscriberInterface
3030
*/
3131
private $ttlHeader;
3232

33+
/**
34+
* @var bool
35+
*/
36+
private $keepTtlHeader;
37+
3338
/**
3439
* Header used for backing up the s-maxage.
3540
*
@@ -38,11 +43,13 @@ class CustomTtlListener implements EventSubscriberInterface
3843
public const SMAXAGE_BACKUP = 'FOS-Smaxage-Backup';
3944

4045
/**
41-
* @param string $ttlHeader The header that is used to specify the TTL header
46+
* @param string $ttlHeader The header name that is used to specify the time to live
47+
* @param bool $keepTtlHeader Keep the custom TTL header on the response for later usage (e.g. debugging)
4248
*/
43-
public function __construct($ttlHeader = 'X-Reverse-Proxy-TTL')
49+
public function __construct($ttlHeader = 'X-Reverse-Proxy-TTL', $keepTtlHeader = false)
4450
{
4551
$this->ttlHeader = $ttlHeader;
52+
$this->keepTtlHeader = $keepTtlHeader;
4653
}
4754

4855
/**
@@ -85,7 +92,10 @@ public function cleanResponse(CacheEvent $e)
8592
$response->headers->addCacheControlDirective('s-maxage', $smaxage);
8693
}
8794
}
88-
$response->headers->remove($this->ttlHeader);
95+
96+
if (!$this->keepTtlHeader) {
97+
$response->headers->remove($this->ttlHeader);
98+
}
8999
$response->headers->remove(static::SMAXAGE_BACKUP);
90100
}
91101

0 commit comments

Comments
 (0)