Skip to content

Commit

Permalink
Redirect response wrapper should commit response
Browse files Browse the repository at this point in the history
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
  • Loading branch information
yuezk authored and bclozel committed Sep 7, 2022
1 parent 8dcb2a7 commit 298c9a6
Showing 1 changed file with 5 additions and 1 deletion.
Expand Up @@ -16,6 +16,8 @@

package org.springframework.web.filter;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;

Expand Down Expand Up @@ -44,9 +46,11 @@ private RelativeRedirectResponseWrapper(HttpServletResponse response, HttpStatus


@Override
public void sendRedirect(String location) {
public void sendRedirect(String location) throws IOException {
resetBuffer();
setStatus(this.redirectStatus.value());
setHeader(HttpHeaders.LOCATION, location);
flushBuffer();
}


Expand Down

0 comments on commit 298c9a6

Please sign in to comment.