Skip to content

Commit 4fbea31

Browse files
authored
Merge pull request #20897 from nextcloud/bugfix/httpcache
Proxy server could cache http response when it is not private
2 parents ab2df70 + 979dd1b commit 4fbea31

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

lib/public/AppFramework/Http/Response.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,11 @@ public function __construct() {
105105
* @return $this
106106
* @since 6.0.0 - return value was added in 7.0.0
107107
*/
108-
public function cacheFor(int $cacheSeconds) {
108+
public function cacheFor(int $cacheSeconds, bool $public = false) {
109109
if ($cacheSeconds > 0) {
110-
$this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate');
111-
112-
// Old scool prama caching
113-
$this->addHeader('Pragma', 'public');
110+
$pragma = $public ? 'public' : 'private';
111+
$this->addHeader('Cache-Control', $pragma . ', max-age=' . $cacheSeconds . ', must-revalidate');
112+
$this->addHeader('Pragma', $pragma);
114113

115114
// Set expires header
116115
$expires = new \DateTime();

tests/lib/AppFramework/Http/ResponseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public function testChainability() {
267267
$this->assertEquals(Http::STATUS_NOT_FOUND, $this->childResponse->getStatus());
268268
$this->assertEquals('hi', $this->childResponse->getEtag());
269269
$this->assertEquals('Thu, 01 Jan 1970 00:00:01 +0000', $headers['Last-Modified']);
270-
$this->assertEquals('max-age=33, must-revalidate',
270+
$this->assertEquals('private, max-age=33, must-revalidate',
271271
$headers['Cache-Control']);
272272
}
273273

0 commit comments

Comments
 (0)