Skip to content

Commit 17e492e

Browse files
committed
Polish
Issue: SPR-11129
1 parent 7df2576 commit 17e492e

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@
195195
* The entity body will be converted to the response stream using
196196
* {@linkplain org.springframework.http.converter.HttpMessageConverter message
197197
* converters}.
198+
* <li>An {@link org.springframework.http.HttpHeaders HttpHeaders} object to
199+
* return a response with no body.</li>
198200
* <li>A {@link Callable} which is used by Spring MVC to obtain the return
199201
* value asynchronously in a separate thread transparently managed by Spring MVC
200202
* on behalf of the application.

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpHeadersReturnValueHandler.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,18 @@ public boolean supportsReturnType(MethodParameter returnType) {
4141

4242
@Override
4343
public void handleReturnValue(Object returnValue, MethodParameter returnType,
44-
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
44+
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
45+
4546
mavContainer.setRequestHandled(true);
4647

4748
Assert.isInstanceOf(HttpHeaders.class, returnValue);
4849
HttpHeaders headers = (HttpHeaders) returnValue;
4950

50-
HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class);
51-
ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(response);
5251
if (!headers.isEmpty()) {
52+
HttpServletResponse servletResponse = webRequest.getNativeResponse(HttpServletResponse.class);
53+
ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(servletResponse);
5354
outputMessage.getHeaders().putAll(headers);
55+
outputMessage.getBody(); // flush headers
5456
}
55-
outputMessage.getBody(); // flush headers
5657
}
5758
}

src/asciidoc/index.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29033,9 +29033,10 @@ The following are the supported return types:
2903329033
* If the method is annotated with `@ResponseBody`, the return type is written to the
2903429034
response HTTP body. The return value will be converted to the declared method argument
2903529035
type using `HttpMessageConverter` s. See <<mvc-ann-responsebody>>.
29036-
* A `HttpEntity<?>` or `ResponseEntity<?>` object to provide access to the Servlet
29036+
* An `HttpEntity<?>` or `ResponseEntity<?>` object to provide access to the Servlet
2903729037
response HTTP headers and contents. The entity body will be converted to the response
2903829038
stream using `HttpMessageConverter` s. See <<mvc-ann-httpentity>>.
29039+
* An `HttpHeaders` object to return a response with no body.
2903929040
* A `Callable<?>` can be returned when the application wants to produce the return value
2904029041
asynchronously in a thread managed by Spring MVC.
2904129042
* A `DeferredResult<?>` can be returned when the application wants to produce the return

0 commit comments

Comments
 (0)