Unwrap HttpHeaders in MultiValueMap constructor

Prior to this commit, `HttpHeaders(MultiValueMap)` stored its argument
as-is. Code compiled against Framework 6.x still links to this
constructor when passing an `HttpHeaders`, which is no longer a
`MultiValueMap`. The resulting instance failed later with an
`IncompatibleClassChangeError`.

This commit unwraps `HttpHeaders` arguments in the constructor and in
`formatHeaders(MultiValueMap)`, as is already done for
`HttpHeaders(HttpHeaders)`.

Closes gh-37358
This commit is contained in:
Brian Clozel
2026-10-09 16:40:08 +02:00
parent a073366444
commit ff46d4b326
@@ -454,7 +454,7 @@ public class HttpHeaders implements Serializable {
*/
public HttpHeaders(MultiValueMap<String, String> headers) {
Assert.notNull(headers, "MultiValueMap must not be null");
this.headers = headers;
this.headers = (headers instanceof HttpHeaders httpHeaders ? unwrap(httpHeaders) : headers);
}
/**
@@ -2115,6 +2115,11 @@ public class HttpHeaders implements Serializable {
* @since 5.1.4
*/
public static String formatHeaders(MultiValueMap<String, String> headers) {
return doFormatHeaders(headers instanceof HttpHeaders httpHeaders ?
unwrap(httpHeaders) : headers);
}
private static String doFormatHeaders(MultiValueMap<String, String> headers) {
Set<String> headerNames = new CaseInsensitiveHeaderNameSet(headers);
String suffix = "]";
if (headerNames.size() != headers.size()) {