Add caching headers for public previews

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2019-01-02 22:27:46 +01:00
parent 273849a7e7
commit 3828283c01
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
2 changed files with 8 additions and 2 deletions

View File

@ -119,7 +119,9 @@ class PublicPreviewController extends PublicShareController {
} }
$f = $this->previewManager->getPreview($file, $x, $y, !$a); $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) { } catch (NotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND); return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
@ -166,7 +168,9 @@ class PublicPreviewController extends PublicShareController {
} }
$f = $this->previewManager->getPreview($node, -1, -1, false); $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) { } catch (NotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND); return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {

View File

@ -136,6 +136,7 @@ class PublicPreviewControllerTest extends TestCase {
$res = $this->controller->getPreview('token', 'file', 10, 10, true); $res = $this->controller->getPreview('token', 'file', 10, 10, true);
$expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']); $expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']);
$expected->cacheFor(3600 * 24);
$this->assertEquals($expected, $res); $this->assertEquals($expected, $res);
} }
@ -190,6 +191,7 @@ class PublicPreviewControllerTest extends TestCase {
$res = $this->controller->getPreview('token', 'file', 10, 10, true); $res = $this->controller->getPreview('token', 'file', 10, 10, true);
$expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']); $expected = new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => 'myMime']);
$expected->cacheFor(3600 * 24);
$this->assertEquals($expected, $res); $this->assertEquals($expected, $res);
} }
} }