1111use Flowpack \FullPageCache \Aspects \ContentCacheAspect ;
1212use Flowpack \FullPageCache \Cache \MetadataAwareStringFrontend ;
1313
14- class CacheHeaderMiddleware implements MiddlewareInterface
14+ class FusionAutoconfigurationMiddleware implements MiddlewareInterface
1515{
16+ public const HEADER_ENABLED = 'X-FullPageCache-EnableFusionAutoconfiguration ' ;
1617
1718 /**
1819 * @Flow\Inject
@@ -32,41 +33,24 @@ class CacheHeaderMiddleware implements MiddlewareInterface
3233 */
3334 protected $ enabled ;
3435
35- /**
36- * @var boolean
37- * @Flow\InjectConfiguration(path="maxPublicCacheTime")
38- */
39- protected $ maxPublicCacheTime ;
40-
4136 public function process (ServerRequestInterface $ request , RequestHandlerInterface $ next ): ResponseInterface
4237 {
4338 if (!$ this ->enabled || !$ request ->hasHeader (RequestCacheMiddleware::HEADER_ENABLED )) {
44- return $ next ->handle ($ request );
39+ return $ next ->handle ($ request )-> withoutHeader ( self :: HEADER_ENABLED ) ;
4540 }
4641
4742 $ response = $ next ->handle ($ request );
4843
49- list ($ hasUncachedSegments , $ tags , $ lifetime ) = $ this ->getFusionCacheInformations ();
50-
51- if ($ response ->hasHeader ('Set-Cookie ' ) || $ hasUncachedSegments ) {
44+ if (!$ response ->hasHeader (self ::HEADER_ENABLED )) {
5245 return $ response ;
46+ } else {
47+ $ response = $ response ->withoutHeader (self ::HEADER_ENABLED );
5348 }
5449
55- $ publicLifetime = 0 ;
56- if ($ this ->maxPublicCacheTime > 0 ) {
57- if ($ lifetime > 0 && $ lifetime < $ this ->maxPublicCacheTime ) {
58- $ publicLifetime = $ lifetime ;
59- } else {
60- $ publicLifetime = $ this ->maxPublicCacheTime ;
61- }
62- }
50+ list ($ hasUncachedSegments , $ tags , $ lifetime ) = $ this ->getFusionCacheInformations ();
6351
64- if ($ publicLifetime > 0 ) {
65- $ entryContentHash = md5 ($ response ->getBody ()->getContents ());
66- $ response ->getBody ()->rewind ();
67- $ response = $ response
68- ->withHeader ('ETag ' , '" ' . $ entryContentHash . '" ' )
69- ->withHeader ('CacheControl ' , 'public, max-age= ' . $ publicLifetime );
52+ if ($ response ->hasHeader ('Set-Cookie ' ) || $ hasUncachedSegments ) {
53+ return $ response ;
7054 }
7155
7256 $ response = $ response
0 commit comments