RFR: 8283544: HttpClient GET method adds Content-Length: 0 header [v3]
Michael McMahon
michaelm at openjdk.java.net
Wed Mar 30 19:31:35 UTC 2022
On Tue, 29 Mar 2022 19:43:50 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:
>> src/java.net.http/share/classes/jdk/internal/net/http/Http1Request.java line 302:
>>
>>> 300:
>>> 301: // GET with no body should not set the Content-Length header
>>> 302: if (requestPublisher != null || !"GET".equals(request.method())) {
>>
>> Can we remove the check for "GET"? This way we will let the users decide if they want to send content-length or not, regardless of the chosen request method.
>
> Practically that would mean not sending Content-Length: 0 by default for GET, DELETE, and HEAD. All other requests methods would have either a Content-Length or Transfer-Encoding. I suspect that HEAD should probably be handled the same way than GET. But should DELETE not have a body? I know that some servers will balk if DELETE has a body. But would they expect Content-Length: 0 not to be included? @Michael-Mc-Mahon what do you think?
RFC 7230 section 3.3.2 says:
"A user agent SHOULD NOT send a
Content-Length header field when the request message does not contain
a payload body and the method semantics do not anticipate such a
body."
I don't think the DELETE method anticipates a a request body. So, it shouldn't have a Content-Length header either IMO. Same for HEAD also.
-------------
PR: https://git.openjdk.java.net/jdk/pull/8017
More information about the net-dev
mailing list