Add seeOther shortcut to ServerResponse.BodyBuilder
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user