Closed
Description
Einar Pehrson [Atlassian] opened SPR-15066 and commented
When using HttpEntity
to make a request with RestTemplate
, the HttpHeaders
passed to ClientHttpRequestInterceptor
s is mutable but with immutable values.
Steps to Reproduce
- Create a
RestTemplate
with aClientHttpRequestInterceptor
that adds a value for a particular header - Create an
HttpEntity
with anHttpHeaders
containing a different value for that same header - Make a request using any of the
RestTemplate
methods that accepts anHttpEntity
Actual Results
An UnsupportedOperationException
is thrown.
java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableCollection.add(Collections.java:1055)
at org.springframework.http.HttpHeaders.add(HttpHeaders.java:1343)
at ...intercept(...)
at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:85)
at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:69)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:666)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:627)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:545)
Expected Results
The request is sent with both values for the header.
Affects: 4.3.5
Reference URL: #1277
Backported to: 4.3.14