RFR: 8283544: HttpClient GET method adds Content-Length: 0 header
Daniel Fuchs
dfuchs at openjdk.java.net
Tue Mar 29 17:12:50 UTC 2022
On Tue, 29 Mar 2022 15:44:58 GMT, Conor Cleary <ccleary at openjdk.org> wrote:
> **Issue**
> When using the `HttpClient.send()` to send a GET request created using the `HttpRequest.newBuilder()`, a `Content-length: 0` header is set. This behaviour causes issues with many services as a body related header is usually not expected to be included with a GET request.
>
> **Solution**
> `Http1Request.java` was modified so that when the request method is a GET, a `Content-length` header is not added to the request. However, if a developer chooses to include a body in a GET request (though it is generally considered bad practice), a `Content-length` header with the appropriate value will be added.
I would not expect that throwing an AssertionError in the handler on the server side would make the client (and the test) fail (except maybe in timeout?). I'd suggest printing a message on System.err and sending a different error code (like 400 for instance) if expectations are not met, and have the client side checks that it receives 200.
-------------
PR: https://git.openjdk.java.net/jdk/pull/8017
More information about the net-dev
mailing list