@@ -84,7 +84,24 @@ public function testNoCustomTtl(): void
84
84
$ this ->assertFalse ($ response ->headers ->has (CustomTtlListener::SMAXAGE_BACKUP ));
85
85
}
86
86
87
- public function testCleanup (): void
87
+ public function testNoCustomTtlNoFallback ()
88
+ {
89
+ $ ttlListener = new CustomTtlListener ('X-Reverse-Proxy-TTL ' , false , false );
90
+ $ request = Request::create ('http://example.com/foo ' , 'GET ' );
91
+ $ response = new Response ('' , 200 , [
92
+ 'Cache-Control ' => 'max-age=30, s-maxage=33 ' ,
93
+ ]);
94
+ $ event = new CacheEvent ($ this ->kernel , $ request , $ response );
95
+
96
+ $ ttlListener ->useCustomTtl ($ event );
97
+ $ response = $ event ->getResponse ();
98
+
99
+ $ this ->assertInstanceOf (Response::class, $ response );
100
+ $ this ->assertSame ('0 ' , $ response ->headers ->getCacheControlDirective ('s-maxage ' ));
101
+ $ this ->assertTrue ($ response ->headers ->has (CustomTtlListener::SMAXAGE_BACKUP ));
102
+ }
103
+
104
+ public function testCleanup ()
88
105
{
89
106
$ ttlListener = new CustomTtlListener ();
90
107
$ request = Request::create ('http://example.com/foo ' , 'GET ' );
@@ -105,7 +122,27 @@ public function testCleanup(): void
105
122
$ this ->assertFalse ($ response ->headers ->has (CustomTtlListener::SMAXAGE_BACKUP ));
106
123
}
107
124
108
- public function testCleanupNoSmaxage (): void
125
+ public function testCleanupNoReverseProxyTtl ()
126
+ {
127
+ $ ttlListener = new CustomTtlListener ();
128
+ $ request = Request::create ('http://example.com/foo ' , 'GET ' );
129
+ $ response = new Response ('' , 200 , [
130
+ 'Cache-Control ' => 's-maxage=0, max-age=30 ' ,
131
+ CustomTtlListener::SMAXAGE_BACKUP => '60 ' ,
132
+ ]);
133
+ $ event = new CacheEvent ($ this ->kernel , $ request , $ response );
134
+
135
+ $ ttlListener ->cleanResponse ($ event );
136
+ $ response = $ event ->getResponse ();
137
+
138
+ $ this ->assertInstanceOf (Response::class, $ response );
139
+ $ this ->assertTrue ($ response ->headers ->hasCacheControlDirective ('s-maxage ' ));
140
+ $ this ->assertSame ('60 ' , $ response ->headers ->getCacheControlDirective ('s-maxage ' ));
141
+ $ this ->assertFalse ($ response ->headers ->has ('X-Reverse-Proxy-TTL ' ));
142
+ $ this ->assertFalse ($ response ->headers ->has (CustomTtlListener::SMAXAGE_BACKUP ));
143
+ }
144
+
145
+ public function testCleanupNoSmaxage ()
109
146
{
110
147
$ ttlListener = new CustomTtlListener ();
111
148
$ request = Request::create ('http://example.com/foo ' , 'GET ' );
0 commit comments