mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Merge branch '6.2.x'
This commit is contained in:
+18
@@ -898,6 +898,23 @@ class DispatcherServletTests {
|
||||
assertThat(response.getHeader("Test-Header")).isEqualTo("spring");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldResetContentTypeIfNotCommitted() throws Exception {
|
||||
StaticWebApplicationContext context = new StaticWebApplicationContext();
|
||||
context.setServletContext(getServletContext());
|
||||
context.registerSingleton("/error", ErrorController.class);
|
||||
DispatcherServlet servlet = new DispatcherServlet(context);
|
||||
servlet.init(servletConfig);
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/error");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
public static class ControllerFromParent implements Controller {
|
||||
|
||||
@@ -950,6 +967,7 @@ class DispatcherServletTests {
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
response.setStatus(400);
|
||||
response.setHeader("Test-Header", "spring");
|
||||
response.addHeader("Content-Type", "application/json");
|
||||
if (request.getAttribute("commit") != null) {
|
||||
response.flushBuffer();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user