Affects: 4.3.24

We have a requirement to set the Host header with our own some "xyz" value and use it in Nginx.

By debugging the code here, I found that one Host header is set with a value of URI in Netty4ClientHttpRequest class using a Set method. The other headers are added in line 143 using the add method.

As a result, when this piece of code runs, there are two Host header one with the value of URI and one with our own "xyz" value, and the Host header with a value of URI takes precedence and it hides our Host header with "xyz" value.

Is there any way possible by which we can override the Host header with our own value?

Comment From: bclozel

Hi @krunalyadav

Unfortunately, Spring Framework 4.3 is officially EOL, please upgrade at your earliest convenience.

We've also deprecated this support in 5.0 in favor of the new WebClient: this Netty client implementation is not efficient and we don't intend to evolve RestTemplate anymore. WebClient is a more modern approach to this problem space.

Now back to this particular issue: client code should not be in the business of setting such headers, as the request factory is ultimately responsible for setting those. By the time the request reaches the factory, things might have changed thanks to interceptors. In your case, the developer can act on this part by changing the request URI. For the same reason, you can configure a custom ClientHttpRequestInterceptor and update the host part of the request URL - this will be reflected in the Host request header.

Thanks,