HttpHeaders.writeableHttpHeaders should unwrap many times
Prior to this commit, the `HttpHeaders.writeableHttpHeaders` would only consider headers read-only instances that were wrapped once by `HttpHeaders.readOnlyHttpHeaders`. This does not work when other `HttpHeaders` wrappers are involved in the chain. This commit ensures that `writeableHttpHeaders` unwraps all headers instances down to the actual multivalue map and create a new headers instance out of it. Fixes gh-33789
This commit is contained in:
@@ -1872,7 +1872,10 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
|||||||
if (headers == EMPTY) {
|
if (headers == EMPTY) {
|
||||||
return new HttpHeaders();
|
return new HttpHeaders();
|
||||||
}
|
}
|
||||||
return (headers instanceof ReadOnlyHttpHeaders ? new HttpHeaders(headers.headers) : headers);
|
while (headers.headers instanceof HttpHeaders wrapped) {
|
||||||
|
headers = wrapped;
|
||||||
|
}
|
||||||
|
return new HttpHeaders(headers.headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -57,6 +57,14 @@ class HttpHeadersTests {
|
|||||||
private final HttpHeaders headers = new HttpHeaders();
|
private final HttpHeaders headers = new HttpHeaders();
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void writableHttpHeadersUnwrapsMultiple() {
|
||||||
|
HttpHeaders originalExchangeHeaders = HttpHeaders.readOnlyHttpHeaders(new HttpHeaders());
|
||||||
|
HttpHeaders firewallHeaders = new HttpHeaders(originalExchangeHeaders);
|
||||||
|
HttpHeaders writeable = HttpHeaders.writableHttpHeaders(firewallHeaders);
|
||||||
|
writeable.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getOrEmpty() {
|
void getOrEmpty() {
|
||||||
String key = "FOO";
|
String key = "FOO";
|
||||||
|
|||||||
Reference in New Issue
Block a user