Affects: 5.3.28 and maybe older versions as well

Steps to reproduce:

  1. Create WebClient instance with baseURL which contains the port (WebClient.builder().baseUrl("localhost:8081")... for example).
  2. Try to make a call to any endpoint on that base URL (webClient.uri("/test-endpoint")... or webClient.uri("test-endpoint")... for example).

Actual behavior:

Request is made to localhost/test-endpoint.

Expected behavior:

Request is made to localhost:8081/test-endpoint.

Such behavior is caused by this check in org.springframework.web.util.HierarchicalUriComponents#copyToUriComponentsBuilder.

Documentation says nothing about this behavior, and it is quite illogical to me.

Is there a way to bypass this problem with current Spring version?

Comment From: watari

But it works as expected when base URL contains information about protocol (http:///https://)

Comment From: sbrannen

I believe the underlying cause is the parsing performed in UriComponentsBuilder.fromUriString(String).

Comment From: bclozel

duplicates #31033