Created
June 6, 2013 07:22
-
-
Save tgpfeiffer/5719872 to your computer and use it in GitHub Desktop.
A replacement for S.hostAndPath that takes into account Lift running on a host with a different port and SSL setting than the reverse proxy in front of it.
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
def realHostAndPath(forceNoSsl: Boolean = false): String = | |
S.request.flatMap(req => (Box !! req.request).map(r => { | |
// X-Forwarded-Host contains host *and* port (if not standard) | |
r.header("X-Forwarded-Host") match { | |
case Full(hostAndPort) => | |
r.scheme match { | |
case "http" if r.header("X-SSL").isDefined => | |
"https://" + hostAndPort + S.contextPath | |
case "http" if r.header("X_FORWARDED_PROTO") == Full("https") && !forceNoSsl => | |
// this (correct) URL is not liked well by Java applets, so we allow to override it | |
"https://" + hostAndPort + S.contextPath | |
case sch => sch + "://" + hostAndPort + S.contextPath | |
} | |
case _ => | |
(r.scheme, r.serverPort) match { | |
case ("http", 80) if r.header("X-SSL").isDefined => "https://" + req.hostName + S.contextPath | |
case ("http", 80) => "http://" + req.hostName + S.contextPath | |
case ("https", 443) => "https://" + req.hostName + S.contextPath | |
case (sch, port) => sch + "://" + req.hostName + ":" + port + S.contextPath | |
} | |
} | |
}) | |
).getOrElse("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment