Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ms-tg/3012687 to your computer and use it in GitHub Desktop.
Save ms-tg/3012687 to your computer and use it in GitHub Desktop.
Example usage of GlobalSettings#onRouteRequest in Play framework 2.0.x scala
import play.api._
import mvc._
import controllers.Info.VERSION_PROPERTY
import controllers.Info.DEFAULT_VERSION
object Global extends GlobalSettings {
val VERSION_PROPERTY = "my.property.name"
val DEFAULT_VERSION = "0.0.0"
def WithAppVersionHeader[A](action: Action[A]): Action[A] = {
Action(action.parser) { request =>
val result = action(request)
result match {
case r: PlainResult => r.withHeaders(VERSION_PROPERTY -> System.getProperty(VERSION_PROPERTY, DEFAULT_VERSION))
case _ => result
}
}
}
override def onRouteRequest(request: RequestHeader): Option[Handler] = {
super.onRouteRequest(request).map { handler =>
handler match {
case a: Action[_] => WithAppVersionHeader(a)
case _ => handler
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment