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:32:06 +01:00
parent 4c4161c8c0
commit a4b3111928
2 changed files with 12 additions and 3 deletions
@@ -136,4 +136,14 @@ class HttpEntityTests {
.isEmpty();
}
@Test
void headerAreMutable() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
String body = "foo";
HttpEntity<String> httpEntity = new HttpEntity<>(body, headers);
httpEntity.getHeaders().setContentType(MediaType.APPLICATION_JSON);
}
}