All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.scalatra.SslRequirement.scala Maven / Gradle / Ivy

The newest version!
package org.scalatra

import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
import java.net.URI

trait SslRequirement extends Handler { self: ScalatraKernel =>
  abstract override def handle(req: HttpServletRequest, res: HttpServletResponse) {
    _request.withValue(req) {
      _response.withValue(res) {
        if(!req.isSecure) {
          val oldUri = new URI(req.getRequestURL.toString)
          val url = new URI("https", oldUri.getAuthority, oldUri.getPath, oldUri.getQuery, oldUri.getFragment).toString
          redirect(url)
        } else {
          super.handle(req, res)
        }
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy