Closed
Description
When migrating a project that uses httpclient
4 any TestRestTemplate
that uses detection will drop back to the simple implementation which may silently drop headers.
This issue was found when upgrading https://github.com/spring-guides/gs-rest-service-cors.
That project declares:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
On Spring Boot 2.7 that will allow the "Origin" header to be sent, but on upgrade the TestRestTemplate
instance will instead use the simple implementation. This uses sun.net.www.protocol.http.HttpURLConnection
which will silently drop restricted "Origin" headers.
The fix is to add the following:
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<scope>test</scope>
</dependency>
Since the error is very difficult to diagnose, it might be nice if we could provide some guidance.