Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModelAndView.status does not work with RedirectView #25092

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,7 @@ protected void render(ModelAndView mv, HttpServletRequest request, HttpServletRe
}
try {
if (mv.getStatus() != null) {
request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, mv.getStatus());
response.setStatus(mv.getStatus().value());
}
view.render(mv.getModelInternal(), request, response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1855,6 +1855,18 @@ void modelAndViewWithStatus(boolean usePathPatterns) throws Exception {
assertThat(response.getForwardedUrl()).isEqualTo("view");
}

@PathPatternsParameterizedTest
void modelAndViewWithStatusForRedirect(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ModelAndViewController.class, usePathPatterns);

MockHttpServletRequest request = new MockHttpServletRequest("GET", "/redirect");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);

assertThat(response.getStatus()).isEqualTo(307);
assertThat(response.getRedirectedUrl()).isEqualTo("/path");
}

@PathPatternsParameterizedTest // SPR-14796
void modelAndViewWithStatusInExceptionHandler(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ModelAndViewController.class, usePathPatterns);
Expand Down Expand Up @@ -3759,6 +3771,11 @@ public ModelAndView methodWithHttpStatus(MyEntity object) {
return new ModelAndView("view", HttpStatus.UNPROCESSABLE_ENTITY);
}

@RequestMapping("/redirect")
public ModelAndView methodWithHttpStatusForRedirect(MyEntity object) {
return new ModelAndView("redirect:/path", HttpStatus.TEMPORARY_REDIRECT);
}

@RequestMapping("/exception")
public void raiseException() throws Exception {
throw new TestException();
Expand Down