spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

Forward incoming headers in WebFlux ProxyExchange body requests

Open PreAgile opened this issue 6 months ago • 0 comments

Summary

The WebFlux variant of ProxyExchange.exchange() drops incoming request headers on POST/PUT/PATCH/DELETE-with-body, because the two body-carrying branches skip the addHeaders(...) call that the body-less branches make. Custom headers like Authorization or X-Custom set on the original request never reach the upstream service.

Changes

  • Hoist addHeaders(exchange.getRequest().getHeaders()) to the builder construction site so every branch picks it up
  • Remove the duplicate addHeaders calls from the body-less branches (they were no-ops anyway since addHeaders is idempotent)
  • Add postWithBodyForwardsIncomingHeaders regression test using the existing /proxy/{id} -> /bars wiring

Context

The webmvc variant of ProxyExchange is unaffected: its private headers(BodyBuilder) helper already adds incoming headers on every method, so I kept the fix scoped to the webflux module.

./mvnw -pl spring-cloud-gateway-proxyexchange-webflux test passes locally (28/28).

Fixes gh-2559

PreAgile avatar May 04 '26 05:05 PreAgile