From 1331eb1fb8a93f9d5d809918dfc8bf06506371a2 Mon Sep 17 00:00:00 2001 From: Clement Wong Date: Sun, 10 May 2020 11:06:56 +0200 Subject: [PATCH 1/3] Proxy server could cache http response when it is not private Signed-off-by: Clement Wong --- lib/public/AppFramework/Http/Response.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/public/AppFramework/Http/Response.php b/lib/public/AppFramework/Http/Response.php index a48580c789..27a2fd3a00 100644 --- a/lib/public/AppFramework/Http/Response.php +++ b/lib/public/AppFramework/Http/Response.php @@ -107,10 +107,10 @@ class Response { */ public function cacheFor(int $cacheSeconds) { if ($cacheSeconds > 0) { - $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); + $this->addHeader('Cache-Control', 'private, max-age=' . $cacheSeconds . ', must-revalidate'); // Old scool prama caching - $this->addHeader('Pragma', 'public'); + $this->addHeader('Pragma', 'private'); // Set expires header $expires = new \DateTime(); From 203d85f04563097ff0203d439d5f5cc6f9657ab3 Mon Sep 17 00:00:00 2001 From: Clement Wong Date: Sun, 10 May 2020 20:22:47 +0200 Subject: [PATCH 2/3] Add public argument to Http cacheFor() Signed-off-by: Clement Wong --- lib/public/AppFramework/Http/Response.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/public/AppFramework/Http/Response.php b/lib/public/AppFramework/Http/Response.php index 27a2fd3a00..6f418e4255 100644 --- a/lib/public/AppFramework/Http/Response.php +++ b/lib/public/AppFramework/Http/Response.php @@ -105,12 +105,11 @@ class Response { * @return $this * @since 6.0.0 - return value was added in 7.0.0 */ - public function cacheFor(int $cacheSeconds) { + public function cacheFor(int $cacheSeconds, bool $public = false) { if ($cacheSeconds > 0) { - $this->addHeader('Cache-Control', 'private, max-age=' . $cacheSeconds . ', must-revalidate'); - - // Old scool prama caching - $this->addHeader('Pragma', 'private'); + $pragma = $public ? 'public' : 'private'; + $this->addHeader('Cache-Control', $pragma . ', max-age=' . $cacheSeconds . ', must-revalidate'); + $this->addHeader('Pragma', $pragma); // Set expires header $expires = new \DateTime(); From 21f8cc584c34b834f31b1df5d26df361000fe423 Mon Sep 17 00:00:00 2001 From: Clement Wong Date: Tue, 12 May 2020 11:49:20 +0200 Subject: [PATCH 3/3] Fix http cache test Signed-off-by: Clement Wong --- tests/lib/AppFramework/Http/ResponseTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lib/AppFramework/Http/ResponseTest.php b/tests/lib/AppFramework/Http/ResponseTest.php index e6f88b6a6e..f33d0a0089 100644 --- a/tests/lib/AppFramework/Http/ResponseTest.php +++ b/tests/lib/AppFramework/Http/ResponseTest.php @@ -267,7 +267,7 @@ class ResponseTest extends \Test\TestCase { $this->assertEquals(Http::STATUS_NOT_FOUND, $this->childResponse->getStatus()); $this->assertEquals('hi', $this->childResponse->getEtag()); $this->assertEquals('Thu, 01 Jan 1970 00:00:01 +0000', $headers['Last-Modified']); - $this->assertEquals('max-age=33, must-revalidate', + $this->assertEquals('private, max-age=33, must-revalidate', $headers['Cache-Control']); }