From 7fc1a12a7508952f32c5bab3a6dac28840c5b067 Mon Sep 17 00:00:00 2001 From: Joshua Bauer Date: Thu, 13 Feb 2020 15:36:16 -0800 Subject: [PATCH] Redirect improvements. --- CHANGELOG.md | 5 +++++ .../java/io/sinistral/proteus/server/ServerRequest.java | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d107593..17bdb7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ Proteus Changelog. ## Unreleased ### No issue +**Added redirect mechanism on ServerRequest.** + + +[d7fcc26ab5ff4a7](https://github.com/noboomu/proteus/commit/d7fcc26ab5ff4a7) Joshua Bauer *2020-02-13 22:06:02* + **Cleanup pom.** diff --git a/proteus-core/src/main/java/io/sinistral/proteus/server/ServerRequest.java b/proteus-core/src/main/java/io/sinistral/proteus/server/ServerRequest.java index a7c3179..4114ea7 100644 --- a/proteus-core/src/main/java/io/sinistral/proteus/server/ServerRequest.java +++ b/proteus-core/src/main/java/io/sinistral/proteus/server/ServerRequest.java @@ -181,13 +181,20 @@ public void startAsync(final Executor executor, final Runnable runnable) exchange.dispatch(executor, runnable); } - public void redirect(String location, boolean includeParameters) + /** + * Abort current request and respond with redirect. Returns empty @ServerResponse for convenience. + * @param location + * @param includeParameters + * @return serverResponse + */ + public ServerResponse redirect(String location, boolean includeParameters) { exchange.getResponseHeaders().put(Headers.LOCATION, RedirectBuilder.redirect(exchange, location, includeParameters)); exchange.setStatusCode(302); exchange.endExchange(); + return new ServerResponse<>(); } /**