Created
April 26, 2014 14:30
-
-
Save plaflamme/11321585 to your computer and use it in GitHub Desktop.
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
object RedirectFilter extends SimpleFilter[HttpRequest, HttpResponse] { | |
def apply(req: HttpRequest, serv: Service[HttpRequest, HttpResponse] = { | |
serv(req) | |
.flatMap { res => | |
if(res.statusCode == 302) { // Obviously, you can handle 301 and 307 as well | |
val uri = res.headers.get("Location") | |
// You'll want to check if uri is to the same host. | |
// You'll want to copy all of req (headers, body, etc) and only replace uri, this is incomplete: | |
val redirect = RequestBuilder().create.uri(uri).buildGet | |
serv(redirect) | |
} else Future.const(res) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment