Skip to content

Instantly share code, notes, and snippets.

@kareblak
Forked from hamnis/SecureKit.scala
Last active December 10, 2015 21:18
Show Gist options
  • Save kareblak/4493655 to your computer and use it in GitHub Desktop.
Save kareblak/4493655 to your computer and use it in GitHub Desktop.
package unfilteredx.kit
import unfiltered.request._
import unfiltered.response._
object Secure {
def secure[A,B](intent: unfiltered.Cycle.Intent[A,B]) = {
case req@ForwardedProto(proto) if (intent.isDefinedAt(req)) => intent(wrap(req, "https" == proto.toLowerCase))
case req if (intent.isDefinedAt(req)) => intent(req)
}
private def wrap[A](req: HttpRequest[A], secure: Boolean) = new DelegatingRequest(req) {
override def isSecure = secure
}
}
object ForwardedProto extends StringHeader("Forwarded-Proto")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment