Skip to content
Snippets Groups Projects
Unverified Commit 211926c0 authored by Morris Jobke's avatar Morris Jobke Committed by GitHub
Browse files

Merge pull request #13326 from nextcloud/bugfix/13290/cache-public-preview

Add caching headers for public previews
parents 969f89f8 3828283c
No related branches found
No related tags found
No related merge requests found
......@@ -119,7 +119,9 @@ class PublicPreviewController extends PublicShareController {
}
$f = $this->previewManager->getPreview($file, $x, $y, !$a);
return new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]);
$response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]);
$response->cacheFor(3600 * 24);
return $response;
} catch (NotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (\InvalidArgumentException $e) {
......@@ -166,7 +168,9 @@ class PublicPreviewController extends PublicShareController {
}
$f = $this->previewManager->getPreview($node, -1, -1, false);
return new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]);
$response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]);
$response->cacheFor(3600 * 24);
return $response;
} catch (NotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (\InvalidArgumentException $e) {
......
......@@ -136,6 +136,7 @@ class PublicPreviewControllerTest extends TestCase {
$res = $this->controller->getPreview('token', 'file', 10, 10, true);
$expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']);
$expected->cacheFor(3600 * 24);
$this->assertEquals($expected, $res);
}
......@@ -190,6 +191,7 @@ class PublicPreviewControllerTest extends TestCase {
$res = $this->controller->getPreview('token', 'file', 10, 10, true);
$expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']);
$expected->cacheFor(3600 * 24);
$this->assertEquals($expected, $res);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment