Add seeOther shortcut to ServerResponse.BodyBuilder

This commit is contained in:
Sebastien Deleuze
2017-03-13 11:32:49 +01:00
parent f84580c32d
commit 3c26e7f014
2 changed files with 22 additions and 0 deletions

View File

@@ -128,6 +128,17 @@ public interface ServerResponse {
return status(HttpStatus.NO_CONTENT);
}
/**
* Create a builder with a {@linkplain HttpStatus#SEE_OTHER 303 See Other}
* status and a location header set to the given URI.
* @param location the location URI
* @return the created builder
*/
static BodyBuilder seeOther(URI location) {
BodyBuilder builder = status(HttpStatus.SEE_OTHER);
return builder.location(location);
}
/**
* Create a builder with a {@linkplain HttpStatus#TEMPORARY_REDIRECT 307 Temporary Redirect}
* status and a location header set to the given URI.

View File

@@ -105,6 +105,17 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void seeOther() throws Exception {
URI location = URI.create("http://example.com");
Mono<ServerResponse> result = ServerResponse.seeOther(location).build();
StepVerifier.create(result)
.expectNextMatches(response -> HttpStatus.SEE_OTHER.equals(response.statusCode()) &&
location.equals(response.headers().getLocation()))
.expectComplete()
.verify();
}
@Test
public void temporaryRedirect() throws Exception {
URI location = URI.create("http://example.com");