@@ -1133,7 +1133,7 @@ public function testEsiCacheSendsTheLowestTtl()
1133
1133
array (
1134
1134
'status ' => 200 ,
1135
1135
'body ' => 'Hello World! ' ,
1136
- 'headers ' => array ('Cache-Control ' => 's-maxage=300 ' ),
1136
+ 'headers ' => array ('Cache-Control ' => 's-maxage=200 ' ),
1137
1137
),
1138
1138
array (
1139
1139
'status ' => 200 ,
@@ -1147,8 +1147,33 @@ public function testEsiCacheSendsTheLowestTtl()
1147
1147
$ this ->request ('GET ' , '/ ' , array (), array (), true );
1148
1148
$ this ->assertEquals ('Hello World! My name is Bobby. ' , $ this ->response ->getContent ());
1149
1149
1150
- // check for 100 or 99 as the test can be executed after a second change
1151
- $ this ->assertTrue (in_array ($ this ->response ->getTtl (), array (99 , 100 )));
1150
+ $ this ->assertEquals (100 , $ this ->response ->getTtl ());
1151
+ }
1152
+
1153
+ public function testEsiCacheSendsTheLowestTtlForHeadRequests ()
1154
+ {
1155
+ $ responses = array (
1156
+ array (
1157
+ 'status ' => 200 ,
1158
+ 'body ' => 'I am a long-lived master response, but I embed a short-lived resource: <esi:include src="/foo" /> ' ,
1159
+ 'headers ' => array (
1160
+ 'Cache-Control ' => 's-maxage=300 ' ,
1161
+ 'Surrogate-Control ' => 'content="ESI/1.0" ' ,
1162
+ ),
1163
+ ),
1164
+ array (
1165
+ 'status ' => 200 ,
1166
+ 'body ' => 'I am a short-lived resource ' ,
1167
+ 'headers ' => array ('Cache-Control ' => 's-maxage=100 ' ),
1168
+ ),
1169
+ );
1170
+
1171
+ $ this ->setNextResponses ($ responses );
1172
+
1173
+ $ this ->request ('HEAD ' , '/ ' , array (), array (), true );
1174
+
1175
+ $ this ->assertEmpty ($ this ->response ->getContent ());
1176
+ $ this ->assertEquals (100 , $ this ->response ->getTtl ());
1152
1177
}
1153
1178
1154
1179
public function testEsiCacheForceValidation ()
@@ -1184,6 +1209,37 @@ public function testEsiCacheForceValidation()
1184
1209
$ this ->assertTrue ($ this ->response ->headers ->hasCacheControlDirective ('no-cache ' ));
1185
1210
}
1186
1211
1212
+ public function testEsiCacheForceValidationForHeadRequests ()
1213
+ {
1214
+ $ responses = array (
1215
+ array (
1216
+ 'status ' => 200 ,
1217
+ 'body ' => 'I am the master response and use expiration caching, but I embed another resource: <esi:include src="/foo" /> ' ,
1218
+ 'headers ' => array (
1219
+ 'Cache-Control ' => 's-maxage=300 ' ,
1220
+ 'Surrogate-Control ' => 'content="ESI/1.0" ' ,
1221
+ ),
1222
+ ),
1223
+ array (
1224
+ 'status ' => 200 ,
1225
+ 'body ' => 'I am the embedded resource and use validation caching ' ,
1226
+ 'headers ' => array ('ETag ' => 'foobar ' ),
1227
+ ),
1228
+ );
1229
+
1230
+ $ this ->setNextResponses ($ responses );
1231
+
1232
+ $ this ->request ('HEAD ' , '/ ' , array (), array (), true );
1233
+
1234
+ // The response has been assembled from expiration and validation based resources
1235
+ // This can neither be cached nor revalidated, so it should be private/no cache
1236
+ $ this ->assertEmpty ($ this ->response ->getContent ());
1237
+ $ this ->assertNull ($ this ->response ->getTtl ());
1238
+ $ this ->assertTrue ($ this ->response ->mustRevalidate ());
1239
+ $ this ->assertTrue ($ this ->response ->headers ->hasCacheControlDirective ('private ' ));
1240
+ $ this ->assertTrue ($ this ->response ->headers ->hasCacheControlDirective ('no-cache ' ));
1241
+ }
1242
+
1187
1243
public function testEsiRecalculateContentLengthHeader ()
1188
1244
{
1189
1245
$ responses = array (
@@ -1192,7 +1248,6 @@ public function testEsiRecalculateContentLengthHeader()
1192
1248
'body ' => '<esi:include src="/foo" /> ' ,
1193
1249
'headers ' => array (
1194
1250
'Content-Length ' => 26 ,
1195
- 'Cache-Control ' => 's-maxage=300 ' ,
1196
1251
'Surrogate-Control ' => 'content="ESI/1.0" ' ,
1197
1252
),
1198
1253
),
@@ -1210,6 +1265,37 @@ public function testEsiRecalculateContentLengthHeader()
1210
1265
$ this ->assertEquals (12 , $ this ->response ->headers ->get ('Content-Length ' ));
1211
1266
}
1212
1267
1268
+ public function testEsiRecalculateContentLengthHeaderForHeadRequest ()
1269
+ {
1270
+ $ responses = array (
1271
+ array (
1272
+ 'status ' => 200 ,
1273
+ 'body ' => '<esi:include src="/foo" /> ' ,
1274
+ 'headers ' => array (
1275
+ 'Content-Length ' => 26 ,
1276
+ 'Surrogate-Control ' => 'content="ESI/1.0" ' ,
1277
+ ),
1278
+ ),
1279
+ array (
1280
+ 'status ' => 200 ,
1281
+ 'body ' => 'Hello World! ' ,
1282
+ 'headers ' => array (),
1283
+ ),
1284
+ );
1285
+
1286
+ $ this ->setNextResponses ($ responses );
1287
+
1288
+ $ this ->request ('HEAD ' , '/ ' , array (), array (), true );
1289
+
1290
+ // https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13
1291
+ // "The Content-Length entity-header field indicates the size of the entity-body,
1292
+ // in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD
1293
+ // method, the size of the entity-body that would have been sent had the request
1294
+ // been a GET."
1295
+ $ this ->assertEmpty ($ this ->response ->getContent ());
1296
+ $ this ->assertEquals (12 , $ this ->response ->headers ->get ('Content-Length ' ));
1297
+ }
1298
+
1213
1299
public function testClientIpIsAlwaysLocalhostForForwardedRequests ()
1214
1300
{
1215
1301
$ this ->setNextResponse ();
@@ -1301,6 +1387,35 @@ public function testEsiCacheRemoveValidationHeadersIfEmbeddedResponses()
1301
1387
$ this ->assertNull ($ this ->response ->getLastModified ());
1302
1388
}
1303
1389
1390
+ public function testEsiCacheRemoveValidationHeadersIfEmbeddedResponsesAndHeadRequest ()
1391
+ {
1392
+ $ time = \DateTime::createFromFormat ('U ' , time ());
1393
+
1394
+ $ responses = array (
1395
+ array (
1396
+ 'status ' => 200 ,
1397
+ 'body ' => '<esi:include src="/hey" /> ' ,
1398
+ 'headers ' => array (
1399
+ 'Surrogate-Control ' => 'content="ESI/1.0" ' ,
1400
+ 'ETag ' => 'hey ' ,
1401
+ 'Last-Modified ' => $ time ->format (DATE_RFC2822 ),
1402
+ ),
1403
+ ),
1404
+ array (
1405
+ 'status ' => 200 ,
1406
+ 'body ' => 'Hey! ' ,
1407
+ 'headers ' => array (),
1408
+ ),
1409
+ );
1410
+
1411
+ $ this ->setNextResponses ($ responses );
1412
+
1413
+ $ this ->request ('HEAD ' , '/ ' , array (), array (), true );
1414
+ $ this ->assertEmpty ($ this ->response ->getContent ());
1415
+ $ this ->assertNull ($ this ->response ->getETag ());
1416
+ $ this ->assertNull ($ this ->response ->getLastModified ());
1417
+ }
1418
+
1304
1419
public function testDoesNotCacheOptionsRequest ()
1305
1420
{
1306
1421
$ this ->setNextResponse (200 , array ('Cache-Control ' => 'public, s-maxage=60 ' ), 'get ' );
0 commit comments