dependency: org.springframework:spring-web:5.3.29 Class: EncoderHttpMessageWriter

Hy, I need to forward a request as-is to another server, so basically my server only acts as a proxy. I use the org.springframework.web.reactive.function.client.WebClient and in the REST endpoint I have this code proxyExchange.uri(requestUri).forward().awaitFirst()

The response that comes back here might contain the header "Transfer-Encoding" - which is perfectly fine. The problem is that the EncoderHttpMessageWriter always sets the header "Content-Length" regardless the response headers that are already present. This seems to be unavoidable if Mono is used. These two headers then cause the client to deny the response from my proxy server, because they must not be returned at the same time.

Comment From: bclozel

This is not a bug in Spring Framework, but rather a feature to be implemented in your application. There are many headers that should not be forwarded on the way in/out when you're proxying requests: some security headers, Transfer-Encoding and more. See https://github.com/spring-projects/spring-framework/issues/21523#issuecomment-819407037 for similar cases.

You can check out the Spring Cloud Gateway project to assess whether you should use it or check out what it takes to proxy HTTP requests properly.

Comment From: jonahermy

Thanks a lot for the very fast and informative response - that really helps a lot :+1: :smile: