Skip to content

Error in RestTemplate when setting the same HTTP header through ClientHttpRequestInterceptor and HttpEntity [SPR-15066] #19632

Closed
@spring-projects-issues

Description

@spring-projects-issues

Einar Pehrson [Atlassian] opened SPR-15066 and commented

When using HttpEntity to make a request with RestTemplate, the HttpHeaders passed to ClientHttpRequestInterceptors is mutable but with immutable values.

Steps to Reproduce

  1. Create a RestTemplate with a ClientHttpRequestInterceptor that adds a value for a particular header
  2. Create an HttpEntity with an HttpHeaders containing a different value for that same header
  3. Make a request using any of the RestTemplate methods that accepts an HttpEntity

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

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions