Add headers in InterceptingClientHttpRequest
This commit *adds* the "intercepted" headers to the ClientHttpRequest, as opposed to replacing them, which is what happened before this commit. Issue: SPR-15166
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1333,14 +1333,17 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
*/
|
||||
@Override
|
||||
public void add(String headerName, String headerValue) {
|
||||
List<String> headerValues = this.headers.get(headerName);
|
||||
if (headerValues == null) {
|
||||
headerValues = new LinkedList<>();
|
||||
this.headers.put(headerName, headerValues);
|
||||
}
|
||||
List<String> headerValues =
|
||||
this.headers.computeIfAbsent(headerName, k -> new LinkedList<>());
|
||||
headerValues.add(headerValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAll(String key, List<String> values) {
|
||||
List<String> currentValues = this.headers.computeIfAbsent(key, k -> new LinkedList<>());
|
||||
currentValues.addAll(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the given, single header value under the given name.
|
||||
* @param headerName the header name
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -86,7 +87,9 @@ class InterceptingClientHttpRequest extends AbstractBufferingClientHttpRequest {
|
||||
}
|
||||
else {
|
||||
ClientHttpRequest delegate = requestFactory.createRequest(request.getURI(), request.getMethod());
|
||||
delegate.getHeaders().putAll(request.getHeaders());
|
||||
for (Map.Entry<String, List<String>> entry : request.getHeaders().entrySet()) {
|
||||
delegate.getHeaders().addAll(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (body.length > 0) {
|
||||
StreamUtils.copy(body, delegate.getBody());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user