Skip to content

Fix duplicate Content-Length handling in DefaultClient#3448

Open
hutiefang76 wants to merge 1 commit into
OpenFeign:masterfrom
hutiefang76:codex/openfeign-2862-content-length
Open

Fix duplicate Content-Length handling in DefaultClient#3448
hutiefang76 wants to merge 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant