org.scalatra.SslRequirement.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalatra_2.9.0-1 Show documentation
Show all versions of scalatra_2.9.0-1 Show documentation
The core Scalatra framework
The newest version!
package org.scalatra
import java.net.URI
/**
* Redirects unsecured requests to the corresponding secure URL.
*/
trait SslRequirement extends Handler {
abstract override def handle(req: RequestT, res: ResponseT) {
if (!req.isSecure) {
val oldUri = req.uri
val port = securePortMap.lift(oldUri.getPort) getOrElse 443
val uri = new URI(
"https", oldUri.getRawUserInfo, oldUri.getHost, port,
oldUri.getPath, oldUri.getQuery, oldUri.getFragment).toString
res.redirect(uri)
} else {
super.handle(req, res)
}
}
/**
* Maps unsecured ports to secure ports. By default, 80 redirects to
* 443, and 8080 to 8443.
*/
protected def securePortMap: PartialFunction[Int, Int] =
Map(80 -> 443, 8080 -> 8443)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy