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

EncoderHttpMessageWriter sets Content-Length even if Transfer-Encoding header is present #32572

Closed
jonahermy opened this issue Apr 3, 2024 · 2 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid

Comments

@jonahermy
Copy link

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 3, 2024
@snicoll snicoll added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Apr 3, 2024
@bclozel
Copy link
Member

bclozel commented Apr 3, 2024

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 #21523 (comment) 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.

@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2024
@bclozel bclozel added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 3, 2024
@jonahermy
Copy link
Author

Thanks a lot for the very fast and informative response - that really helps a lot 👍 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

4 participants