Skip to content

Commit 0f94587

Browse files
committed
Only reset response buffer for error handling
Prior to this commit, `DispatcherServlet` would completely reset the response (status, headers and body) before handling errors within Spring MVC. This can cause unintended consequences when Servlet Filters added response headers before the error happened. Such response headers might be still required in case of error handling. This commit changes the complete reset of the response to only resetting the response buffer, if possible. Closes gh-31154 See gh-31104
1 parent 88ee8fc commit 0f94587

File tree

2 files changed

+61
-57
lines changed

2 files changed

+61
-57
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1338,9 +1338,10 @@ protected ModelAndView processHandlerException(HttpServletRequest request, HttpS
13381338

13391339
// Success and error responses may use different content types
13401340
request.removeAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE);
1341-
// Reset the response if the response is not committed already
1341+
// Reset the response body buffer if the response is not committed already,
1342+
// leaving the response headers in place.
13421343
try {
1343-
response.reset();
1344+
response.resetBuffer();
13441345
}
13451346
catch (IllegalStateException illegalStateException) {
13461347
// the response is already committed, leave it to exception handlers anyway

0 commit comments

Comments
 (0)