8000 Improved Cache-Control header when no-cache is sent · symfony/symfony@1ab4923 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ab4923

Browse files
dlsniperfabpot
authored andcommitted
Improved Cache-Control header when no-cache is sent
1 parent f853fc3 commit 1ab4923

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ public function prepare(Request $request)
245245
$this->setProtocolVersion('1.1');
246246
}
247247

248+
// Check if we need to send extra expire info headers
249+
if ('1.0' == $this->getProtocolVersion() && 'no-cache' == $this->headers->get('Cache-Control')) {
250+
$this->headers->set('pragma', 'no-cache');
251+
$this->headers->set('expires', -1);
252+
}
253+
248254
return $this;
249255
}
250256

@@ -686,8 +692,14 @@ public function getMaxAge()
686692
return $age;
687693
}
688694

689-
if (null !== $this->getExpires()) {
690-
return $this->getExpires()->format('U') - $this->getDate()->format('U');
695+
$expiry = $this->getExpires();
696+
697+
if (!$expiry instanceof \DateTime && (-1 == $expiry || 0 === $expiry)) {
698+
return $expiry;
699+
}
700+
701+
if (null !== $expiry) {
702+
return $expiry->format('U') - $this->getDate()->format('U');
691703
}
692704

693705
return null;

0 commit comments

Comments
 (0)
0