Redirect response wrapper should commit response

This commit ensures that when using `sendRedirect`, the response wrapper
behaves correctly with regards to the Servlet specification:

1. reset the response buffer to clear any partially written response
2. set the expected response HTTP headers
3. flush the buffer to commit the response

Closes gh-29050
This commit is contained in:
Kevin Yue 2022-08-31 10:57:16 -04:00 committed by Brian Clozel
parent 8dcb2a75fa
commit 298c9a6f1b
1 changed files with 5 additions and 1 deletions

View File

@ -16,6 +16,8 @@
package org.springframework.web.filter;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
@ -44,9 +46,11 @@ final class RelativeRedirectResponseWrapper extends HttpServletResponseWrapper {
@Override
public void sendRedirect(String location) {
public void sendRedirect(String location) throws IOException {
resetBuffer();
setStatus(this.redirectStatus.value());
setHeader(HttpHeaders.LOCATION, location);
flushBuffer();
}