4

I have a simple method to send a POST request:

public HttpResponse post(InputStream content, String contentType, URI url) {
    InputStreamEntity entity = new InputStreamEntity(content);
    entity.setChunked(true);
    entity.setContentType(contentType);

    HttpPost httpPost = new HttpPost(url);
    httpPost.setEntity(entity)

    return httpClient.execute(httpPost, httpContext);
}

The httpPost seems well configured:

  • httpPost.getEntity().toString() = [Content-Type: application/json,Chunked: true]
  • httpPost.getEntity().getContentLength() = -1

But the remote server receives Content-Length header

A request on http://httpbin.org/post shows the actual headers are:

"headers":{
    "Accept-Encoding": "gzip,deflate",
    "Content-Length": "571",
    "Content-Type": "application/json",
    "Host": "httpbin.org",
    "User-Agent": "blabla",
    "Via": "1.1 localhost (Apache-HttpClient/4.5.2 (cache))"
}

=> Does org.apache.http.client 4.5 really support chunked-encoding or does it fake it ?

Thank you

Pleymor
  • 2,611
  • 1
  • 32
  • 44

1 Answers1

1

Chunked data is definitely supported by Apache HttpClient.

Httpbin.org relies on Nginx and I guess buffering of proxy's requests is enabled in their configuration. Consequently, you do not see chunked transfer encoding in the result returned by httpbin.

Instead of using an external service such as httpbin.org for checking this kind of headers, use your own webserver.

Math
  • 33
  • 3