Details
-
Improvement
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
5.2.2
Description
When making a POST request with an empty body, the following difference in behaviour was observed.
In HttpComponents 4.4.x, a null body causes a Content-Length zero header to be added.
In HttpComponents 5.2.x, a null body causes no Content-Length headers being added.
While upgrading an Apache Camel application, we noticed that this breaks calls to an upstream IIS server which replies with 411 (Length Required).
That server expects either a Content-Length 0 or a Transfer-Encoding: chunked header (with a chunk-size of zero) on requests that have a body semantic (POST, PUT).
As the code currently stands written, if we manually set `Content-Length: 0` a ProtocolException is thrown RequestContent.java:106
and if we call the constructor with overwrite, this header is removed anyway without being replaced.
The previous behaviour (4.x) is documented RequestContent.java:102
A suggested fix: re-add the null check and set Content-Length to zero.