Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/gallery.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2018-07-28 12:34:25 +0300
committerJulius Härtl <jus@bitgrid.net>2018-07-28 12:34:58 +0300
commit28c469f6ce8c1af9e62a2e940a5dea43d0218022 (patch)
treec8218721f8a56722243acf9417d2a0ca351d6ffa /lib
parent739ce553cf7f58d3c744029857aed2d24c49d789 (diff)
Add proper ETag check
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/PreviewController.php12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/Controller/PreviewController.php b/lib/Controller/PreviewController.php
index d2ff041b..576f7a8f 100644
--- a/lib/Controller/PreviewController.php
+++ b/lib/Controller/PreviewController.php
@@ -12,6 +12,7 @@
namespace OCA\Gallery\Controller;
+use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\ILogger;
@@ -122,10 +123,14 @@ class PreviewController extends Controller {
* @param int $width
* @param int $height
*
- * @return ImageResponse|Http\JSONResponse
+ * @return DataResponse|ImageResponse|JSONResponse
*/
public function getPreview($fileId, $width, $height) {
/** @type File $file */
+ list($file, $status) = $this->getFile($fileId);
+ if ($this->request->getHeader('If-None-Match') === $file->getEtag()) {
+ return new DataResponse([], Http::STATUS_NOT_MODIFIED);
+ }
list($file, $preview, $status) = $this->getData($fileId, $width, $height);
if (!$preview) {
@@ -140,7 +145,10 @@ class PreviewController extends Controller {
$response = new ImageResponse($preview, $status);
$response->setETag($file->getEtag());
- $response->cacheFor(3600 * 24);
+ $lastModified = new \DateTime();
+ $lastModified->setTimestamp($file->getMTime());
+ $response->setLastModified($lastModified);
+ $response->cacheFor(3600*24);
return $response;
}