Last active
July 6, 2018 10:33
-
-
Save mbseid/8327841 to your computer and use it in GitHub Desktop.
Play Framework 2 HTTPS Redirect
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
override def onRouteRequest(req: RequestHeader): Option[Handler] = { | |
(req.method, req.headers.get("X-Forwarded-Proto")) match { | |
case ("GET", Some(protocol)) if protocol != "https" => Some(Action{ MovedPermanently("https://"+req.host+req.uri)}) | |
case (_, _) => super.onRouteRequest(req) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Play 2.3 provides a secure property in the request object.
I have updated your code for Play v 2.3.
It automatically use auto redirect to https protocol on the server side, but locally work by http protocol for development.