Set status code on DefaultRenderingBuilder for RedirectView
See gh-33498
This commit is contained in:
@@ -85,6 +85,9 @@ class DefaultRenderingBuilder implements Rendering.RedirectBuilder {
|
||||
@Override
|
||||
public DefaultRenderingBuilder status(HttpStatusCode status) {
|
||||
this.status = status;
|
||||
if (this.view instanceof RedirectView) {
|
||||
((RedirectView) this.view).setStatusCode(status);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +126,15 @@ class DefaultRenderingBuilderTests {
|
||||
assertThat(((RedirectView) view).isPropagateQuery()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void redirectWithCustomStatus() {
|
||||
Rendering rendering = Rendering.redirectTo("foo").status(HttpStatus.MOVED_PERMANENTLY).build();
|
||||
|
||||
Object view = rendering.view();
|
||||
assertThat(view.getClass()).isEqualTo(RedirectView.class);
|
||||
assertThat(((RedirectView) view).statusCode()).isEqualTo(HttpStatus.MOVED_PERMANENTLY);
|
||||
}
|
||||
|
||||
|
||||
private static class Foo {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user