@@ -348,6 +348,127 @@ public function testLoadsBodyEval()
348
348
$ this ->assertSame ($ content , $ response ->getContent ());
349
349
}
350
350
351
+ /**
352
+ * Basic case when the second header has a different value.
353
+ * Both responses should be cached
354
+ */
355
+ public function testWriteWithMultipleVaryAndCachedAllResponse ()
356
+ {
357
+ $ req1 = Request::create ('/foo ' , 'get ' , [], [], [], ['HTTP_FOO ' => 'foo ' , 'HTTP_BAR ' => 'bar ' ]);
358
+ $ content = str_repeat ('a ' , 24 ).'b ' .str_repeat ('a ' , 24 );
359
+ $ res1 = new Response ($ content , 200 , ['vary ' => ['Foo ' , 'Bar ' ], 'X-Body-Eval ' => 'SSI ' ]);
360
+ $ this ->store ->write ($ req1 , $ res1 );
361
+
362
+ $ responseLook = $ this ->store ->lookup ($ req1 );
363
+ $ this ->assertSame ($ content , $ responseLook ->getContent ());
364
+
365
+ $ req2 = Request::create ('/foo ' , 'get ' , [], [], [], ['HTTP_FOO ' => 'foo ' , 'HTTP_BAR ' => 'foobar ' ]);
366
+ $ content2 = str_repeat ('b ' , 24 ).'a ' .str_repeat ('b ' , 24 );
367
+ $ res2 = new Response ($ content2 , 200 , ['vary ' => ['Foo ' , 'Bar ' ], 'X-Body-Eval ' => 'SSI ' ]);
368
+ $ this ->store ->write ($ req2 , $ res2 );
369
+
370
+ $ responseLook = $ this ->store ->lookup ($ req2 );
371
+ $ this ->assertSame ($ content2 , $ responseLook ->getContent ());
372
+
373
+ $ responseLook = $ this ->store ->lookup ($ req1 );
374
+ $ this ->assertSame ($ content , $ responseLook ->getContent ());
375
+ }
376
+
377
+ /**
378
+ * Basic case when the second header has the same value on both requests.
379
+ * The last response should be cached
380
+ */
381
+ public function testWriteWithMultipleVaryAndCachedLastResponse ()
382
+ {
383
+ $ req1 = Request::create ('/foo ' , 'get ' , [], [], [], ['HTTP_FOO ' => 'foo ' , 'HTTP_BAR ' => 'bar ' ]);
384
+ $ content = str_repeat ('a ' , 24 ).'b ' .str_repeat ('a ' , 24 );
385
+ $ res1 = new Response ($ content , 200 , ['vary ' => ['Foo ' , 'Bar ' ], 'X-Body-Eval ' => 'SSI ' ]);
386
+ $ this ->store ->write ($ req1 , $ res1 );
387
+
388
+ $ responseLook = $ this ->store ->lookup ($ req1 );
389
+ $ this ->assertSame ($ content , $ responseLook ->getContent ());
390
+
391
+ $ req2 = Request::create ('/foo ' , 'get ' , [], [], [], ['HTTP_FOO ' => 'foo ' , 'HTTP_BAR ' => 'bar ' ]);
392
+ $ content2 = str_repeat ('b ' , 24 ).'a ' .str_repeat ('b ' , 24 );
393
+ $ res2 = new Response ($ content2 , 200 , ['vary ' => ['Foo ' , 'Bar ' ], 'X-Body-Eval ' => 'SSI ' ]);
394
+ $ this ->store ->write ($ req2 , $ res2 );
395
+
396
+ $ responseLook = $ this ->store ->lookup ($ req2 );
397
+ $ this ->assertSame ($ content2 , $ responseLook ->getContent ());
398
+
399
+ $ responseLook = $ this ->store ->lookup ($ req1 );
400
+ $ this ->assertSame ($ content2 , $ responseLook ->getContent ());
401
+ }
402
+
403
+ /**
404
+ * Case when a vary value has been removed.
405
+ * Both responses should be cached
406
+ */
407
+ public function testWriteWithChangingVary ()
408
+ {
409
+ $ req1 = Request::create ('/foo ' , 'get ' , [], [], [], ['HTTP_FOO ' => 'foo ' , 'HTTP_BAR ' => 'bar ' ]);
410
+ $ content = str_repeat ('a ' , 24 ).'b ' .str_repeat ('a ' , 24 );
411
+ $ res1 = new Response ($ content , 200 , ['vary ' => ['Foo ' , 'bar ' , 'foobar ' ], 'X-Body-Eval ' => 'SSI ' ]);
412
+ $ this ->store ->write ($ req1 , $ res1 );
413
+
414
+ $ req2 = Request::create ('/foo ' , 'get ' , [], [], [], ['HTTP_FOO ' => 'foo ' , 'HTTP_FOOBAR ' => 'bar ' ]);
415
+ $ content2 = str_repeat ('b ' , 24 ).'a ' .str_repeat ('b ' , 24 );
416
+ $ res2 = new Response ($ content2 , 200 , ['vary ' => ['Foo ' , 'foobar ' ], 'X-Body-Eval ' => 'SSI ' ]);
417
+ $ this ->store ->write ($ req2 , $ res2 );
418
+
419
+ $ responseLook = $ this ->store ->lookup ($ req2 );
420
+ $ this ->assertSame ($ content2 , $ responseLook ->getContent ());
421
+
422
+ $ responseLook = $ this ->store ->lookup ($ req1 );
423
+ $ this ->assertSame ($ content , $ responseLook ->getContent ());
424
+ }
425
+
426
+ /**
427
+ * Case when a vary value has been removed and headers of the new vary list are the same.
428
+ * The last response should be cached
429
+ */
430
+ public function testWriteWithRemoveVaryAndAllHeadersOnTheList ()
431
+ {
432
+ $ req1 = Request::create ('/foo ' , 'get ' , [], [], [], ['HTTP_FOO ' => 'foo ' , 'HTTP_FOOBAR ' => 'bar ' ,]);
433
+ $ content = str_repeat ('a ' , 24 ).'b ' .str_repeat ('a ' , 24 );
434
+ $ res1 = new Response ($ content , 200 , ['vary ' => ['Foo ' , 'bar ' , 'foobar ' ], 'X-Body-Eval ' => 'SSI ' ]);
435
+ $ this ->store ->write ($ req1 , $ res1 );
436
+
437
+ $ req2 = Request::create ('/foo ' , 'get ' , [], [], [], ['HTTP_FOO ' => 'foo ' , 'HTTP_FOOBAR ' => 'bar ' ]);
438
+ $ content2 = str_repeat ('b ' , 24 ).'a ' .str_repeat ('b ' , 24 );
439
+ $ res2 = new Response ($ content2 , 200 , ['vary ' => ['Foo ' , 'foobar ' ], 'X-Body-Eval ' => 'SSI ' ]);
440
+ $ this ->store ->write ($ req2 , $ res2 );
441
+
442
+ $ responseLook = $ this ->store ->lookup ($ req2 );
443
+ $ this ->assertSame ($ content2 , $ responseLook ->getContent ());
444
+
445
+ $ responseLook = $ this ->store ->lookup ($ req1 );
446
+ $ this ->assertSame ($ content2 , $ responseLook ->getContent ());
447
+ }
448
+
449
+ /**
450
+ * Case when a vary value has been added and headers of the new vary list are the same.
451
+ * The last response should be cached
452
+ */
453
+ public function testWriteWithAddingVaryAndAllHeadersOnTheList ()
454
+ {
455
+ $ req1 = Request::create ('/foo ' , 'get ' , [], [], [], ['HTTP_FOO ' => 'foo ' , 'HTTP_FOOBAR ' => 'bar ' ]);
456
+ $ content = str_repeat ('a ' , 24 ).'b ' .str_repeat ('a ' , 24 );
457
+ $ res1 = new Response ($ content , 200 , ['vary ' => ['Foo ' , 'foobar ' ], 'X-Body-Eval ' => 'SSI ' ]);
458
+ $ this ->store ->write ($ req1 , $ res1 );
459
+
460
+ $ req2 = Request::create ('/foo ' , 'get ' , [], [], [], ['HTTP_FOO ' => 'foo ' , 'HTTP_BAR ' => 'foobar ' , 'HTTP_FOOBAR ' => 'bar ' ]);
461
+ $ content2 = str_repeat ('b ' , 24 ).'a ' .str_repeat ('b ' , 24 );
462
+ $ res2 = new Response ($ content2 , 200 , ['vary ' => ['Foo ' , 'bar ' , 'foobar ' ], 'X-Body-Eval ' => 'SSI ' ]);
463
+ $ this ->store ->write ($ req2 , $ res2 );
464
+
465
+ $ responseLook = $ this ->store ->lookup ($ req2 );
466
+ $ this ->assertSame ($ content2 , $ responseLook ->getContent ());
467
+
468
+ $ responseLook = $ this ->store ->lookup ($ req1 );
469
+ $ this ->assertSame ($ content , $ responseLook ->getContent ());
470
+ }
471
+
351
472
protected function storeSimpleEntry ($ path = null , $ headers = [])
352
473
{
353
474
$ path ??= '/test ' ;
0 commit comments