Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading from Spring Boot 2.7 to 3.0 doesn't flag httpcomponents changes #33515

Closed
philwebb opened this issue Dec 12, 2022 · 2 comments
Closed
Labels
type: wiki-documentation A documentation update required on the wiki

Comments

@philwebb
Copy link
Member

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.

@martinqcz
Copy link

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.

@bclozel
Copy link
Member

bclozel commented Jan 20, 2023

We've added a note in the migration guide.

@scottfrederick scottfrederick added type: wiki-documentation A documentation update required on the wiki and removed type: bug A general bug labels Feb 1, 2023
@scottfrederick scottfrederick removed this from the 3.0.x milestone Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: wiki-documentation A documentation update required on the wiki
Projects
None yet
Development

No branches or pull requests

5 participants