Skip to content

Commit 99e4815

Browse files
committed
Merge branch '6.2.x'
2 parents c23edae + 6bd12e8 commit 99e4815

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,7 @@ protected HandlerAdapter getHandlerAdapter(Object handler) throws ServletExcepti
12131213
// leaving the other response headers in place.
12141214
try {
12151215
response.setHeader(HttpHeaders.CONTENT_TYPE, null);
1216+
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, null);
12161217
response.resetBuffer();
12171218
}
12181219
catch (IllegalStateException illegalStateException) {

spring-webmvc/src/test/java/org/springframework/web/servlet/DispatcherServletTests.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -898,8 +898,8 @@ void shouldAttemptToResetResponseBufferIfCommitted() throws Exception {
898898
assertThat(response.getHeader("Test-Header")).isEqualTo("spring");
899899
}
900900

901-
@Test
902-
void shouldResetContentTypeIfNotCommitted() throws Exception {
901+
@Test // gh-34366, gh-35116
902+
void shouldResetContentHeadersIfNotCommitted() throws Exception {
903903
StaticWebApplicationContext context = new StaticWebApplicationContext();
904904
context.setServletContext(getServletContext());
905905
context.registerSingleton("/error", ErrorController.class);
@@ -908,11 +908,15 @@ void shouldResetContentTypeIfNotCommitted() throws Exception {
908908

909909
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/error");
910910
MockHttpServletResponse response = new MockHttpServletResponse();
911-
assertThatThrownBy(() -> servlet.service(request, response)).isInstanceOf(ServletException.class)
911+
912+
assertThatThrownBy(() -> servlet.service(request, response))
913+
.isInstanceOf(ServletException.class)
912914
.hasCauseInstanceOf(IllegalArgumentException.class);
915+
913916
assertThat(response.getContentAsByteArray()).isEmpty();
914917
assertThat(response.getStatus()).isEqualTo(400);
915918
assertThat(response.getHeaderNames()).doesNotContain(HttpHeaders.CONTENT_TYPE);
919+
assertThat(response.getHeaderNames()).doesNotContain(HttpHeaders.CONTENT_DISPOSITION);
916920
}
917921

918922

@@ -968,6 +972,7 @@ public ModelAndView handleRequest(HttpServletRequest request, HttpServletRespons
968972
response.setStatus(400);
969973
response.setHeader("Test-Header", "spring");
970974
response.addHeader("Content-Type", "application/json");
975+
response.addHeader("Content-Disposition", "attachment; filename=\"report.txt\"");
971976
if (request.getAttribute("commit") != null) {
972977
response.flushBuffer();
973978
}

0 commit comments

Comments
 (0)