Skip to content

Instantly share code, notes, and snippets.

@julienrf
Created July 5, 2015 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julienrf/4847fe7d6e76c68dbea9 to your computer and use it in GitHub Desktop.
Save julienrf/4847fe7d6e76c68dbea9 to your computer and use it in GitHub Desktop.
Handling Etags with Play
def taggedResult(request: RequestHeader, tag: String)(result: => Result): Result =
request.headers.get(IF_NONE_MATCH) match {
case Some(t) if t == tag => NotModified
case _ => result.withHeaders(ETAG -> tag)
}
// Example of use:
val javascriptRoutes = {
val router =
JavaScriptReverseRouter("routes", None, hostname,
routes.javascript.Controller.search,
routes.javascript.Controller.geocode
)
val routerTag = router.body.hashCode.toString
Action { request =>
taggedResult(request, routerTag) {
Ok(JavaScript(s"""define(function () { ${router.body}; return routes })"""))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment