On Fri, 6 May 2022 10:33:31 GMT, Conor Cleary <ccle...@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.
>
> Conor Cleary has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   8283544: Improved logging, drain input stream

Changes requested by dfuchs (Reviewer).

src/java.net.http/share/classes/jdk/internal/net/http/Http1Request.java line 
311:

> 309:                 streaming = true;
> 310:                 systemHeadersBuilder.setHeader("Transfer-encoding", 
> "chunked");
> 311:             }

With that - and if I'm not mistaken, lines 294-299 can be removed now.

test/jdk/java/net/httpclient/ContentLengthHeaderTest.java line 105:

> 103:                 .uri(URI.create(testContentLengthURI + NO_BODY_PATH))
> 104:                 .build();
> 105:         HttpClient hc = HttpClient.newHttpClient();

It would be better to reuse the same client for all tests. Also better to 
configure it with NO_PROXY.

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

PR: https://git.openjdk.java.net/jdk/pull/8017

Reply via email to