Skip to content

Instantly share code, notes, and snippets.

@stephanos
Created May 14, 2012 16:25
Show Gist options
  • Select an option

  • Save stephanos/2694899 to your computer and use it in GitHub Desktop.

Select an option

Save stephanos/2694899 to your computer and use it in GitHub Desktop.
play https
protected case class Encrypted[A](action: Action[A]) extends Action[A] {
def apply(req: Request[A]) = {
EnvUtil.isCloud match {
case true =>
req.headers.get("x-forwarded-proto") match {
case Some("https") => action(req)
case _ => redirectToHttps(req)
}
case _ =>
action(req)
}
}
lazy val parser = action.parser
}
protected def redirectToHttps(req: RequestHeader, customPath: String = null) = {
val protocol = if (EnvUtil.isCloud) "https://" else "http://"
Redirect(protocol + req.headers.get("host").get + Option(customPath).getOrElse(req.uri))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment