RFR: 8358942: HttpClient adds Content-Length: 0 for a GET request with a BodyPublishers.noBody()

Daniel Jeliński djelinski at openjdk.org
Fri Oct 10 10:22:00 UTC 2025


Do not send the Content-Length header on HTTP/1.1 requests when the content length is known to be zero and the method does not expect content or is unknown.

This brings the HTTP/1.1 implementation in line with the recommendations from RFC 9110.

The existing ContentLengthHeaderTest was extended to cover the modified scenarios.

Tier1-3 tests continue to pass.

-------------

Commit messages:
 - Do not send content-length if body is empty and the method doesn't expect any

Changes: https://git.openjdk.org/jdk/pull/27727/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=27727&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8358942
  Stats: 112 lines in 2 files changed: 108 ins; 1 del; 3 mod
  Patch: https://git.openjdk.org/jdk/pull/27727.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/27727/head:pull/27727

PR: https://git.openjdk.org/jdk/pull/27727


More information about the net-dev mailing list