Created
July 5, 2015 08:08
-
-
Save julienrf/4847fe7d6e76c68dbea9 to your computer and use it in GitHub Desktop.
Handling Etags with Play
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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