Last active
November 1, 2015 13:27
-
-
Save cdmckay/792c52d9c7d1d071acc4 to your computer and use it in GitHub Desktop.
HttpsAction
This file contains hidden or 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
package actions | |
import play.api.Play | |
import play.api.Play.current | |
import play.api.mvc._ | |
import scala.concurrent.Future | |
object HttpsAction extends ActionBuilder[Request] with Results { | |
def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]) = { | |
if (Play.isProd && !request.secure) { | |
Future.successful(Redirect(s"https://${request.domain}:443${request.path}", 301)) | |
} else { | |
block(request) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment