Make HttpEntity headers mutables

Since its inception, instantiating an `HttpEntity` makes its
`HttpHeaders` read-only. While immutability is an interesting design
principle, here we shouldn't enforce this.

For example, developers can expect to instantiate a `ResponseEntity`
and still mutate its headers.

Closes gh-35888
This commit is contained in:
Brian Clozel
2025-11-27 16:37:47 +01:00
parent 4c4161c8c0
commit a4b3111928
2 changed files with 12 additions and 3 deletions
@@ -102,7 +102,7 @@ public class HttpEntity<T> {
*/
public HttpEntity(@Nullable T body, @Nullable HttpHeaders headers) {
this.body = body;
this.headers = HttpHeaders.readOnlyHttpHeaders(headers != null ? headers : new HttpHeaders());
this.headers = (headers != null) ? headers : new HttpHeaders();
}
/**
@@ -123,8 +123,7 @@ public class HttpEntity<T> {
*/
@Deprecated(since = "7.0", forRemoval = true)
public HttpEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers) {
this.body = body;
this.headers = HttpHeaders.readOnlyHttpHeaders(headers != null ? new HttpHeaders(headers) : new HttpHeaders());
this(body, (headers != null) ? new HttpHeaders(headers) : new HttpHeaders());
}