You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
I experienced another issue with the TestRestTemplate and Spring Boot 3.0.1. By default it does not allow to use HTTP PATCH method in requests ad throws java.net.ProtocolException: Invalid HTTP method: PATCH
If I add org.apache.httpcomponents.client5:httpclient5 dependency, than it starts to work.
When migrating a project that uses
httpclient
4 anyTestRestTemplate
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:
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 usessun.net.www.protocol.http.HttpURLConnection
which will silently drop restricted "Origin" headers.The fix is to add the following:
Since the error is very difficult to diagnose, it might be nice if we could provide some guidance.
The text was updated successfully, but these errors were encountered: