Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpClient: disabling chunked encoding

I am using the Apache Commons HttpClient along with Restlet to call a restful web service. Unfortunately, my server (based on Ruby on Rails) does not like the Transfer-Encoding: chunked that HttpClient is using by default.

Is there any way to disable the usage of chunked encoding for POSTs from the client?

like image 685
Thilo-Alexander Ginkel Avatar asked Jan 19 '23 13:01

Thilo-Alexander Ginkel


1 Answers

As a general rule, for request not to be chunked, you need to specify exact size of post body, which for dynamically generated data means you need to buffer entire response in memory, see its size and only then send it.

Apache client documentation seems to confirm this: AbstractHttpEntity.setChunked() states

Note that the chunked setting is a hint only. If using HTTP/1.0, chunking is never performed. Otherwise, even if chunked is false, HttpClient must use chunk coding if the entity content length is unknown (-1).

like image 175
Slartibartfast Avatar answered Jan 21 '23 02:01

Slartibartfast