mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
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:
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user