Merge pull request #20897 from nextcloud/bugfix/httpcache

Proxy server could cache http response when it is not private
This commit is contained in:
Roeland Jago Douma 2020-05-13 08:27:05 +02:00 committed by GitHub
commit 4fbea316a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 6 deletions

View File

@ -105,12 +105,11 @@ class Response {
* @return $this * @return $this
* @since 6.0.0 - return value was added in 7.0.0 * @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) { if ($cacheSeconds > 0) {
$this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); $pragma = $public ? 'public' : 'private';
$this->addHeader('Cache-Control', $pragma . ', max-age=' . $cacheSeconds . ', must-revalidate');
// Old scool prama caching $this->addHeader('Pragma', $pragma);
$this->addHeader('Pragma', 'public');
// Set expires header // Set expires header
$expires = new \DateTime(); $expires = new \DateTime();

View File

@ -267,7 +267,7 @@ class ResponseTest extends \Test\TestCase {
$this->assertEquals(Http::STATUS_NOT_FOUND, $this->childResponse->getStatus()); $this->assertEquals(Http::STATUS_NOT_FOUND, $this->childResponse->getStatus());
$this->assertEquals('hi', $this->childResponse->getEtag()); $this->assertEquals('hi', $this->childResponse->getEtag());
$this->assertEquals('Thu, 01 Jan 1970 00:00:01 +0000', $headers['Last-Modified']); $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']); $headers['Cache-Control']);
} }