From 8760be7d6428e3b54e6486106770fe1a1ac1e18c Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 13 Oct 2014 17:22:27 +0200 Subject: [PATCH] ResponseEntity's HeadersBuilder allows for specifying existing HttpHeaders Issue: SPR-12324 --- .../springframework/http/ResponseEntity.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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)));