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

Daniel Jeliński djelinski at openjdk.org
Fri Oct 10 12:04:31 UTC 2025


On Fri, 10 Oct 2025 11:01:23 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

>> Daniel Jeliński has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Add test explicitly setting content length to zero
>
> 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();

Thanks for the suggestion. I added the test. Note that the `content-length` header is restricted by default, and had to be explicitly allowed.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27727#discussion_r2419735215


More information about the net-dev mailing list