Skip to content

Commit 298c9a6

Browse files
yuezkbclozel
authored andcommitted
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
1 parent 8dcb2a7 commit 298c9a6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

spring-web/src/main/java/org/springframework/web/filter/RelativeRedirectResponseWrapper.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.web.filter;
1818

19+
import java.io.IOException;
20+
1921
import javax.servlet.http.HttpServletResponse;
2022
import javax.servlet.http.HttpServletResponseWrapper;
2123

@@ -44,9 +46,11 @@ private RelativeRedirectResponseWrapper(HttpServletResponse response, HttpStatus
4446

4547

4648
@Override
47-
public void sendRedirect(String location) {
49+
public void sendRedirect(String location) throws IOException {
50+
resetBuffer();
4851
setStatus(this.redirectStatus.value());
4952
setHeader(HttpHeaders.LOCATION, location);
53+
flushBuffer();
5054
}
5155

5256

0 commit comments

Comments
 (0)