From 2ac10e81278becf09c97dce3375f7430e193d0df Mon Sep 17 00:00:00 2001 From: Benjamin Gamard Date: Wed, 14 Mar 2018 19:01:28 +0100 Subject: [PATCH] #182: do not cache the temporary thumbnail --- .../docs/rest/resource/FileResource.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/FileResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/FileResource.java index 85d24074..bc2b2a60 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/FileResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/FileResource.java @@ -525,12 +525,19 @@ public class FileResource extends BaseResource { return Response.status(Status.SERVICE_UNAVAILABLE).build(); } - return Response.ok(stream) + Response.ResponseBuilder builder = Response.ok(stream) .header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=" + file.getFullName("data")) - .header(HttpHeaders.CONTENT_TYPE, mimeType) - .header(HttpHeaders.CACHE_CONTROL, "private") - .header(HttpHeaders.EXPIRES, HttpUtil.buildExpiresHeader(3_600_000L * 24L * 365L)) - .build(); + .header(HttpHeaders.CONTENT_TYPE, mimeType); + if (decrypt) { + // Cache real files + builder.header(HttpHeaders.CACHE_CONTROL, "private") + .header(HttpHeaders.EXPIRES, HttpUtil.buildExpiresHeader(3_600_000L * 24L * 365L)); + } else { + // Do not cache the temporary thumbnail + builder.header(HttpHeaders.CACHE_CONTROL, "no-store, must-revalidate") + .header(HttpHeaders.EXPIRES, "0"); + } + return builder.build(); } /**