http headers - How to set Etag for a url in play framework? -


i have searched set etag in playframework. got are
1) https://www.playframework.com/documentation/2.0/assets
2) https://www.playframework.com/documentation/2.0/javaresponse

first option works asset or files. second option not work. added 3 given in example.

actually usage of etag described in play's doc assets (that linked first) , in wikipedia typical usage section.

at beginning of action need determine if requested resource has been changed since previous generation of etag, if yes, need generate new content new etag, otherwise return 304 notmodified response.

of course depends on kind of requested resource, anyway quite clean sample may database entity, id , field date/time of last modification:

public static result etaggedfoo(long id) {      foo foo = foo.find.byid(id);     if (foo == null) return notfound("given foo not found");      string etag = digestutils.md5hex(foo.id + foo.lastmodification.tostring());      string ifnonematch = request().getheader("if-none-match");     if (ifnonematch != null && ifnonematch.equals(etag)) return status(304);      response().setheader(etag, etag);     return ok("here can see " + foo.name + ", last modified: " + foo.lastmodification.tostring());  } 

Comments

Popular posts from this blog

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -