Skip to content

Commit

Permalink
Set status code on DefaultRenderingBuilder for RedirectView
Browse files Browse the repository at this point in the history
  • Loading branch information
yfoel authored and rstoyanchev committed Sep 9, 2024
1 parent 3d1bf28 commit 7655329
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ private Model initModel() {
@Override
public DefaultRenderingBuilder status(HttpStatusCode status) {
this.status = status;
if (this.view instanceof RedirectView) {
((RedirectView) this.view).setStatusCode(status);
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ void redirectWithPropagateQuery() {
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 {}

Expand Down

0 comments on commit 7655329

Please sign in to comment.