Skip to content

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

Closed
@philwebb

Description

@philwebb

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions