RFR: 8358942: HttpClient adds Content-Length: 0 for a GET request with a BodyPublishers.noBody() [v2]
Daniel Jeliński
djelinski at openjdk.org
Tue Oct 14 15:02:56 UTC 2025
On Mon, 13 Oct 2025 07:31:40 GMT, Volkan Yazici <vyazici 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 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.
That's not possible in most cases: in HTTP/2 and HTTP/3 we don't send the content-length:0 header, we only send content-length when it's known up front and non-zero.
In cases where it is possible it's usually not necessary - most of the time we don't really care if the content length was sent or not, as long as the server is able to figure it out.
I'll add a check for the HTTP/1 + PUT/POST case, since that's special-cased by this PR.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27727#discussion_r2429520632
More information about the net-dev
mailing list