spring-cloud-gateway
spring-cloud-gateway copied to clipboard
Forward incoming headers in WebFlux ProxyExchange body requests
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
addHeaderscalls from the body-less branches (they were no-ops anyway sinceaddHeadersis idempotent) - Add
postWithBodyForwardsIncomingHeadersregression test using the existing/proxy/{id}->/barswiring
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