Allow interceptors to add existing header values
Provide a fully mutable HttpHeaders to ClientHttpRequestInterceptors of a RestTemplate when headers are set using HttpEntity. This avoids UnsupportedOperationException if both HttpEntity and ClientHttpRequestInterceptor add values for the same HTTP header. Issue: SPR-15066
This commit is contained in:
@@ -21,6 +21,7 @@ import java.lang.reflect.Type;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -909,7 +910,9 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
HttpHeaders httpHeaders = httpRequest.getHeaders();
|
||||
HttpHeaders requestHeaders = this.requestEntity.getHeaders();
|
||||
if (!requestHeaders.isEmpty()) {
|
||||
httpHeaders.putAll(requestHeaders);
|
||||
for (Map.Entry<String, List<String>> entry : requestHeaders.entrySet()) {
|
||||
httpHeaders.put(entry.getKey(), new LinkedList<>(entry.getValue()));
|
||||
}
|
||||
}
|
||||
if (httpHeaders.getContentLength() < 0) {
|
||||
httpHeaders.setContentLength(0L);
|
||||
|
||||
Reference in New Issue
Block a user