Support HttpComponents 5.6

This commit updates the HttpComponents HttpClient to refer to the parsed
`HttpEntity` for the content-related HTTP response headers such as
encoding and body length.

Closes gh-36100
This commit is contained in:
Brian Clozel
2026-01-06 16:56:45 +01:00
parent 3027d78f40
commit 97cd9dd03b
3 changed files with 31 additions and 2 deletions
@@ -66,6 +66,16 @@ final class HttpComponentsClientHttpResponse implements ClientHttpResponse {
public HttpHeaders getHeaders() {
if (this.headers == null) {
MultiValueMap<String, String> adapter = new HttpComponentsHeadersAdapter(this.httpResponse);
// update headers if response is decompressed
HttpEntity httpEntity = this.httpResponse.getEntity();
if (httpEntity != null) {
if (httpEntity.getContentLength() == -1) {
adapter.remove(HttpHeaders.CONTENT_LENGTH);
}
if (httpEntity.getContentEncoding() == null) {
adapter.remove(HttpHeaders.CONTENT_ENCODING);
}
}
this.headers = HttpHeaders.readOnlyHttpHeaders(adapter);
}
return this.headers;