RFR: 8358942: HttpClient adds Content-Length: 0 for a GET request with a BodyPublishers.noBody()
Daniel Fuchs
dfuchs at openjdk.org
Fri Oct 10 11:04:18 UTC 2025
On Thu, 9 Oct 2025 13:27:42 GMT, Daniel Jeliński <djelinski at openjdk.org> wrote:
> 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.
test/jdk/java/net/httpclient/ContentLengthHeaderTest.java line 202:
> 200: assertEquals(resp.version(), version);
> 201: }
> 202:
Maybe you should add a test that verifies that Content-Length: 0 is still sent if you do:
HttpRequest req = HttpRequest.newBuilder()
.version(version)
.method("GET", HttpRequest.BodyPublishers.noBody())
.header("Content-Length", "0")
.uri(uri)
.build();
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27727#discussion_r2419447591
More information about the net-dev
mailing list