Flush headers after null StreamingResponseBody

Issue: SPR-14315
This commit is contained in:
Lifu Zhou
2016-05-30 14:38:59 +08:00
committed by Rossen Stoyanchev
parent 71463fb399
commit 7e95cd8b4e
2 changed files with 15 additions and 0 deletions

View File

@@ -29,6 +29,7 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.core.MethodParameter;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
@@ -58,6 +59,8 @@ public class StreamingResponseBodyReturnValueHandlerTests {
private MockHttpServletResponse response;
private HttpHeaders headers = new HttpHeaders();
@Before
public void setUp() throws Exception {
@@ -69,6 +72,8 @@ public class StreamingResponseBodyReturnValueHandlerTests {
this.response = new MockHttpServletResponse();
this.webRequest = new ServletWebRequest(this.request, this.response);
this.headers.add("foo", "bar");
AsyncWebRequest asyncWebRequest = new StandardServletAsyncWebRequest(this.request, this.response);
WebAsyncUtils.getAsyncManager(this.webRequest).setAsyncWebRequest(asyncWebRequest);
this.request.setAsyncSupported(true);
@@ -140,6 +145,14 @@ public class StreamingResponseBodyReturnValueHandlerTests {
assertEquals(204, this.response.getStatus());
}
@Test
public void responseEntityWithHeadersAndNoContent() throws Exception {
MethodParameter returnType = returnType(TestController.class, "handleResponseEntity");
ResponseEntity<?> emitter = ResponseEntity.noContent().headers(headers).build();
this.handler.handleReturnValue(emitter, returnType, this.mavContainer, this.webRequest);
assertEquals(this.response.getHeaders("foo"), this.headers.get("foo"));
}
private MethodParameter returnType(Class<?> clazz, String methodName) throws NoSuchMethodException {
Method method = clazz.getDeclaredMethod(methodName);