Browse Source

Add seeOther shortcut to ServerResponse.BodyBuilder

pull/1357/head
Sebastien Deleuze 9 years ago
parent
commit
3c26e7f014
  1. 11
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerResponse.java
  2. 11
      spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilderTests.java

11
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerResponse.java

@ -128,6 +128,17 @@ public interface ServerResponse {
return status(HttpStatus.NO_CONTENT); 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} * Create a builder with a {@linkplain HttpStatus#TEMPORARY_REDIRECT 307 Temporary Redirect}
* status and a location header set to the given URI. * status and a location header set to the given URI.

11
spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilderTests.java

@ -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 @Test
public void temporaryRedirect() throws Exception { public void temporaryRedirect() throws Exception {
URI location = URI.create("http://example.com"); URI location = URI.create("http://example.com");

Loading…
Cancel
Save