Skip to content

Fix duplicate Content-Length handling in DefaultClient - #3448

Merged
velo merged 1 commit into
OpenFeign:masterfrom
hutiefang76:codex/openfeign-2862-content-length
Jul 28, 2026
Merged

Fix duplicate Content-Length handling in DefaultClient#3448
velo merged 1 commit into
OpenFeign:masterfrom
hutiefang76:codex/openfeign-2862-content-length

Conversation

@hutiefang76

Copy link
Copy Markdown

Fixes #2862.

RequestTemplate.body(...) records the request body length as a Content-Length header. DefaultClient.convertAndSend(...) used that value in two ways for non-compressed request bodies: it kept the length for fixed-length streaming mode and also added it as a normal request property. With HttpURLConnection, the body/output path can manage the request length itself, so adding the header manually can produce duplicate Content-Length values when restricted headers are allowed.

This change keeps the parsed content length for the existing disableRequestBuffering / fixed-length streaming path, but stops adding Content-Length through addRequestProperty(...) for request bodies.

Tests:

mvn -pl core -Dtoolchain.skip=true -Dtest=ClientTest#testConvertAndSendDoesNotAddContentLengthHeaderForBody test
mvn -pl core -Dtoolchain.skip=true -Dtest=ClientTest test
mvn -pl core -Dtoolchain.skip=true -Dtest=DefaultClientTest test
mvn -pl core -Dtoolchain.skip=true test
git diff --check

Note: I used -Dtoolchain.skip=true locally because this machine does not have a Maven JDK 8 toolchain configured; the core module still compiled and ran its test suite successfully.

Signed-off-by: hutiefang <hutiefang@qq.com>

@velo velo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved via agent-assisted review: change includes tests, no backwards-compatibility break, no security concerns, CI green.

@velo
velo merged commit e5a6a54 into OpenFeign:master Jul 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feign.core v13.2.1 Repeatedly writing "Content-Length"

2 participants