diff --git a/spring-web/src/main/java/org/springframework/http/ResponseEntity.java b/spring-web/src/main/java/org/springframework/http/ResponseEntity.java index d63752b4ac..2d7d4b8128 100644 --- a/spring-web/src/main/java/org/springframework/http/ResponseEntity.java +++ b/spring-web/src/main/java/org/springframework/http/ResponseEntity.java @@ -256,13 +256,22 @@ public class ResponseEntity extends HttpEntity { /** * Add the given, single header value under the given name. - * @param headerName the header name + * @param headerName the header name * @param headerValues the header value(s) * @return this builder * @see HttpHeaders#add(String, String) */ B header(String headerName, String... headerValues); + /** + * Copy the given headers into the entity's headers map. + * @param headers the existing HttpHeaders to copy from + * @return this builder + * @since 4.1.2 + * @see HttpHeaders#add(String, String) + */ + B headers(HttpHeaders headers); + /** * Set the set of allowed {@link HttpMethod HTTP methods}, as specified * by the {@code Allow} header. @@ -360,6 +369,12 @@ public class ResponseEntity extends HttpEntity { return this; } + @Override + public BodyBuilder headers(HttpHeaders headers) { + this.headers.putAll(headers); + return this; + } + @Override public BodyBuilder allow(HttpMethod... allowedMethods) { this.headers.setAllow(new HashSet(Arrays.asList(allowedMethods)));