Fix HttpHeaders header-map params losing values via QueryMapEncoder - #1416
Merged
ryanjbaxter merged 1 commit intoSep 9, 2026
Conversation
Since Spring Framework 7, HttpHeaders no longer implements the MultiValueMap contract. A @RequestHeader HttpHeaders parameter is resolved through Feign's generic headerMapIndex path, which falls back to the configured QueryMapEncoder whenever the argument isn't a java.util.Map. That reflects over HttpHeaders' JavaBeans getters via BeanQueryMapEncoder, dropping every real header value and injecting unrelated getter-derived entries (contentLength=-1, date=-1, etc.) instead. Special-case HttpHeaders in PageableSpringQueryMapEncoder, the QueryMapEncoder bean Spring Cloud OpenFeign already registers by default, mirroring the existing Pageable/Sort handling. Fixes spring-cloudgh-1328 Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.com>
Contributor
|
Cherry picked to 5.0.x as well |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes gh-1328
Root cause
Since Spring Framework 7,
HttpHeadersno longer implements theMultiValueMapcontract (onlySerializable). A@RequestHeader HttpHeadersparameter is wired byRequestHeaderParameterProcessoras Feign's genericheaderMapIndex. At invocation time,feign.RequestTemplateFactoryResolver.toQueryMap()only takes the fastinstanceof Mappath for a trueMap; otherwise it delegates to the configuredQueryMapEncoder. Spring Cloud OpenFeign registersPageableSpringQueryMapEncoderas the defaultQueryMapEncoderbean for all Feign clients, and its fallback (BeanQueryMapEncoder) reflects over the object's JavaBeans getter properties.For an
HttpHeadersinstance this means every real header value is dropped, and the map is instead populated with unrelated getter-derived entries (contentLength=-1,date=-1,accept=[], etc.) — reproduced locally:Fix
PageableSpringQueryMapEncoderalready special-casesPageable/Sortinstead of falling through to the generic bean-reflection encoder. This adds the same special-case forHttpHeaders, using its ownforEach(BiConsumer<String, List<String>>)to build the query map directly — mirroring the pattern already established forPageable/Sortin this class.Test
Added
PageableSpringQueryMapEncoderTests#testHttpHeadersRequest, which fails against the old code (asserts a 2-entry map with the real header values) and passes with the fix. Verified locally:spring-cloud-openfeign-core, 441 tests) passes with the change../mvnw validate(checkstyle + spring-javaformat) passes with 0 violations.Verification done: reproduced the exact symptom from gh-1328 locally against current
main(confirmedPageableSpringQueryMapEncoder— the actual defaultQueryMapEncoderbean SCOF wires up — reflectsHttpHeadersviaBeanQueryMapEncoderand drops all real header values); confirmed no in-flight PR/linked branch on the issue; confirmed no AI-contribution policy restriction in CONTRIBUTING.md; new regression test fails on pre-fix code and passes post-fix; full module test suite green; checkstyle/javaformat clean.Disclosure: this change was authored with AI assistance (Claude Code), with the root cause independently traced and verified against the current codebase and the fix manually reviewed before submission.