Commit 4953530d by Anton Sudak

Fix Akka warnings regarding incorrect etag

parent 1c0c3bd7
......@@ -17,40 +17,30 @@
package ch.insign.commons.util;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import play.mvc.Result;
import play.twirl.api.Content;
import static play.mvc.Controller.request;
import static play.mvc.Controller.response;
import static play.mvc.Http.HeaderNames.ETAG;
import static play.mvc.Http.HeaderNames.*;
import static play.mvc.Results.notFound;
import static play.mvc.Results.ok;
import static play.mvc.Results.status;
* Class to create thumbnails
public class Etag {
private final static Logger logger = LoggerFactory.getLogger(Etag.class);
public static Result resultWithETag(Content content) {
if (content == null) {
return notFound("Given Content was not found");
String eTag = DigestUtils.md5Hex(content.body());
String ifNoneMatch = request().getHeader("If-None-Match");
if (ifNoneMatch != null && ifNoneMatch.equals(eTag)) {
return status(304);
String eTag = '"' + DigestUtils.md5Hex(content.body()) + '"';
response().setHeader(ETAG, eTag);
return ok(content);
return request().header(IF_NONE_MATCH)
.<Result>map(h -> status(304))
.orElseGet(() -> ok(content).withHeader(ETAG, eTag));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment