File tree Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -758,8 +758,10 @@ public function getMaxAge(): ?int
758758 return (int ) $ this ->headers ->getCacheControlDirective ('max-age ' );
759759 }
760760
761- if (null !== $ this ->getExpires ()) {
762- return (int ) $ this ->getExpires ()->format ('U ' ) - (int ) $ this ->getDate ()->format ('U ' );
761+ if (null !== $ expires = $ this ->getExpires ()) {
762+ $ maxAge = (int ) $ expires ->format ('U ' ) - (int ) $ this ->getDate ()->format ('U ' );
763+
764+ return max ($ maxAge , 0 );
763765 }
764766
765767 return null ;
@@ -835,7 +837,7 @@ public function setSharedMaxAge(int $value): static
835837 *
836838 * It returns null when no freshness information is present in the response.
837839 *
838- * When the responses TTL is <= 0, the response may not be served from cache without first
840+ * When the response's TTL is 0, the response may not be served from cache without first
839841 * revalidating with the origin.
840842 *
841843 * @final
@@ -844,7 +846,7 @@ public function getTtl(): ?int
844846 {
845847 $ maxAge = $ this ->getMaxAge ();
846848
847- return null !== $ maxAge ? $ maxAge - $ this ->getAge () : null ;
849+ return null !== $ maxAge ? max ( $ maxAge - $ this ->getAge (), 0 ) : null ;
848850 }
849851
850852 /**
Original file line number Diff line number Diff line change @@ -341,9 +341,8 @@ public function testGetMaxAge()
341341 $ this ->assertEquals (3600 , $ response ->getMaxAge (), '->getMaxAge() falls back to Expires when no max-age or s-maxage directive present ' );
342342
343343 $ response = new Response ();
344- $ response ->headers ->set ('Cache-Control ' , 'must-revalidate ' );
345344 $ response ->headers ->set ('Expires ' , -1 );
346- $ this ->assertLessThanOrEqual ( time () - 2 * 86400 , $ response ->getExpires ()-> format ( ' U ' ));
345+ $ this ->assertSame ( 0 , $ response ->getMaxAge ( ));
347346
348347 $ response = new Response ();
349348 $ this ->assertNull ($ response ->getMaxAge (), '->getMaxAge() returns null if no freshness information available ' );
@@ -462,7 +461,7 @@ public function testGetTtl()
462461
463462 $ response = new Response ();
464463 $ response ->headers ->set ('Expires ' , $ this ->createDateTimeOneHourAgo ()->format (\DATE_RFC2822 ));
465- $ this ->assertLessThan (0 , $ response ->getTtl (), '->getTtl() returns negative values when Expires is in past ' );
464+ $ this ->assertSame (0 , $ response ->getTtl (), '->getTtl() returns zero when Expires is in past ' );
466465
467466 $ response = new Response ();
468467 $ response ->headers ->set ('Expires ' , $ response ->getDate ()->format (\DATE_RFC2822 ));
You can’t perform that action at this time.
0 commit comments