From 298c9a6f1bda440dd8aacf2065ea58b85d062261 Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Wed, 31 Aug 2022 10:57:16 -0400 Subject: [PATCH] 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 --- .../web/filter/RelativeRedirectResponseWrapper.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-web/src/main/java/org/springframework/web/filter/RelativeRedirectResponseWrapper.java b/spring-web/src/main/java/org/springframework/web/filter/RelativeRedirectResponseWrapper.java index d532c62513..0d418548c5 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/RelativeRedirectResponseWrapper.java +++ b/spring-web/src/main/java/org/springframework/web/filter/RelativeRedirectResponseWrapper.java @@ -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(); }