diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java
index 8e810ee2ffc..77e8ef5d995 100644
--- a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java
+++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java
@@ -195,6 +195,8 @@ import java.util.concurrent.Callable;
* The entity body will be converted to the response stream using
* {@linkplain org.springframework.http.converter.HttpMessageConverter message
* converters}.
+ *
An {@link org.springframework.http.HttpHeaders HttpHeaders} object to
+ * return a response with no body.
* A {@link Callable} which is used by Spring MVC to obtain the return
* value asynchronously in a separate thread transparently managed by Spring MVC
* on behalf of the application.
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpHeadersReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpHeadersReturnValueHandler.java
index e00d00112fe..680771cde1f 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpHeadersReturnValueHandler.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpHeadersReturnValueHandler.java
@@ -41,17 +41,18 @@ public class HttpHeadersReturnValueHandler implements HandlerMethodReturnValueHa
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType,
- ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
+ ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
+
mavContainer.setRequestHandled(true);
Assert.isInstanceOf(HttpHeaders.class, returnValue);
HttpHeaders headers = (HttpHeaders) returnValue;
- HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class);
- ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(response);
if (!headers.isEmpty()) {
+ HttpServletResponse servletResponse = webRequest.getNativeResponse(HttpServletResponse.class);
+ ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(servletResponse);
outputMessage.getHeaders().putAll(headers);
+ outputMessage.getBody(); // flush headers
}
- outputMessage.getBody(); // flush headers
}
}
diff --git a/src/asciidoc/index.adoc b/src/asciidoc/index.adoc
index 91117426bbb..7e2a5f7ee1a 100644
--- a/src/asciidoc/index.adoc
+++ b/src/asciidoc/index.adoc
@@ -29033,9 +29033,10 @@ The following are the supported return types:
* If the method is annotated with `@ResponseBody`, the return type is written to the
response HTTP body. The return value will be converted to the declared method argument
type using `HttpMessageConverter` s. See <>.
-* A `HttpEntity>` or `ResponseEntity>` object to provide access to the Servlet
+* An `HttpEntity>` or `ResponseEntity>` object to provide access to the Servlet
response HTTP headers and contents. The entity body will be converted to the response
stream using `HttpMessageConverter` s. See <>.
+* An `HttpHeaders` object to return a response with no body.
* A `Callable>` can be returned when the application wants to produce the return value
asynchronously in a thread managed by Spring MVC.
* A `DeferredResult>` can be returned when the application wants to produce the return