RFR: 8358942: HttpClient adds Content-Length: 0 for a GET request with a BodyPublishers.noBody() [v2]
Volkan Yazici
vyazici at openjdk.org
Mon Oct 13 07:34:05 UTC 2025
On Fri, 10 Oct 2025 12:04:28 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.
>
> 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 217:
> 215: assertEquals(resp.statusCode(), 200, resp.body());
> 216: assertEquals(resp.version(), version);
> 217: assertEquals(resp.body(), "Request completed");
If possible, you may consider verifying the response body in other test methods too, since, in particular, `OptionalContentLengthHandler` responds with 200 in two different scenarios.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27727#discussion_r2425435656
More information about the net-dev
mailing list