mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Clear CONTENT_DISPOSITION before error handling
Closes gh-35116
This commit is contained in:
+8
-3
@@ -924,8 +924,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);
|
||||
@@ -934,11 +934,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);
|
||||
}
|
||||
|
||||
|
||||
@@ -994,6 +998,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