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:
Arjen Poutsma
2017-01-30 14:18:46 +01:00
parent b487ed6748
commit 69c16f3821
7 changed files with 62 additions and 29 deletions

View File

@@ -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

View File

@@ -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());
}