[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-2245?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17631691#comment-17631691
 ] 

Yubao Liu commented on HTTPCLIENT-2245:
---------------------------------------

> Why would the performance be better?

 

I guess the server side could tell how much memory will be allocated in one go 
and may just drop the request if it's too big.

 

And why doesn't Apache HC set the "Content-Length"? Any benefit? Save some 
bandwidth? Considering other http client libraries all set "Content-Length" 
which I think is more consistent with common expectation.

> Content-Length is missing for HTTP/2
> ------------------------------------
>
>                 Key: HTTPCLIENT-2245
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2245
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>          Components: HttpClient (async)
>    Affects Versions: 5.1.3, 5.2-beta1
>         Environment: macOS, JDK 17
> openjdk version "17" 2021-09-14
> OpenJDK Runtime Environment Temurin-17+35 (build 17+35)
> OpenJDK 64-Bit Server VM Temurin-17+35 (build 17+35, mixed mode, sharing)
>            Reporter: Yubao Liu
>            Priority: Major
>
> {code:java}
> import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
> import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
> import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
> import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
> import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
> import org.apache.hc.core5.http.ContentType;
> import org.apache.hc.core5.http2.HttpVersionPolicy;
> public class A {
>     public static void main(String[] args) throws Exception {
>         CloseableHttpAsyncClient httpClient = 
> HttpAsyncClientBuilder.create().useSystemProperties()
>             .setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_2)
>             .build();
>         httpClient.start();
>         SimpleHttpRequest request = 
> SimpleRequestBuilder.post("https://httpbin.org/anything";)
>             .setBody("{\"msg\": \"hello\"}".getBytes(), 
> ContentType.APPLICATION_JSON)
>             .build();
>         SimpleHttpResponse response = httpClient.execute(request, null).get();
>         System.out.println(response.getBodyText());
>     }
> }{code}
> According to the response, HttpClient doesn't set content-length 
> automatically:
> {code:java}
> {
>   "args": {}, 
>   "data": "{\"msg\": \"hello\"}", 
>   "files": {}, 
>   "form": {}, 
>   "headers": {
>     "Content-Type": "application/json; charset=UTF-8", 
>     "Host": "httpbin.org", 
>     "Transfer-Encoding": "chunked", 
>     "User-Agent": "Apache-HttpAsyncClient/5.2-beta1 (Java/17)", 
>     "X-Amzn-Trace-Id": "Root=1-636cd35b-506ee990624aebd74fce87b9"
>   }, 
>   "json": {
>     "msg": "hello"
>   }, 
>   "method": "POST", 
>   "origin": "114.246.97.66", 
>   "url": "https://httpbin.org/anything";
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org

Reply via email to