mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-10-10 17:29:17 +00:00
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:
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user