Merge branch '6.2.x'

This commit is contained in:
rstoyanchev
2025-07-09 11:03:49 +01:00
2 changed files with 9 additions and 3 deletions
@@ -1213,6 +1213,7 @@ public class DispatcherServlet extends FrameworkServlet {
// leaving the other response headers in place.
try {
response.setHeader(HttpHeaders.CONTENT_TYPE, null);
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, null);
response.resetBuffer();
}
catch (IllegalStateException illegalStateException) {
@@ -898,8 +898,8 @@ class DispatcherServletTests {
assertThat(response.getHeader("Test-Header")).isEqualTo("spring");
}
@Test
void shouldResetContentTypeIfNotCommitted() throws Exception {
@Test // gh-34366, gh-35116
void shouldResetContentHeadersIfNotCommitted() throws Exception {
StaticWebApplicationContext context = new StaticWebApplicationContext();
context.setServletContext(getServletContext());
context.registerSingleton("/error", ErrorController.class);
@@ -908,11 +908,15 @@ class DispatcherServletTests {
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/error");
MockHttpServletResponse response = new MockHttpServletResponse();
assertThatThrownBy(() -> servlet.service(request, response)).isInstanceOf(ServletException.class)
assertThatThrownBy(() -> servlet.service(request, response))
.isInstanceOf(ServletException.class)
.hasCauseInstanceOf(IllegalArgumentException.class);
assertThat(response.getContentAsByteArray()).isEmpty();
assertThat(response.getStatus()).isEqualTo(400);
assertThat(response.getHeaderNames()).doesNotContain(HttpHeaders.CONTENT_TYPE);
assertThat(response.getHeaderNames()).doesNotContain(HttpHeaders.CONTENT_DISPOSITION);
}
@@ -968,6 +972,7 @@ class DispatcherServletTests {
response.setStatus(400);
response.setHeader("Test-Header", "spring");
response.addHeader("Content-Type", "application/json");
response.addHeader("Content-Disposition", "attachment; filename=\"report.txt\"");
if (request.getAttribute("commit") != null) {
response.flushBuffer();
}