mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Merge branch '6.2.x'
This commit is contained in:
@@ -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) {
|
||||
|
||||
+8
-3
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user