[ 
https://issues.apache.org/jira/browse/HTTPCORE-759?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Billy Jaime Beltran updated HTTPCORE-759:
-----------------------------------------
    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|https://github.com/apache/httpcomponents-core/blob/e3c770b55602eb9e5a45dfe7c6a07a1adede2c95/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestContent.java#L106]
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|https://github.com/apache/httpcomponents-core/blob/a5c117028b7c620974304636d52f06f172f1d08b/httpcore/src/main/java/org/apache/http/protocol/RequestContent.java#L102]

 

A suggested fix: re-add the null check and set Content-Length to zero.

  was:
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|https://github.com/apache/httpcomponents-core/blob/e3c770b55602eb9e5a45dfe7c6a07a1adede2c95/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestContent.java#L106]
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|https://github.com/apache/httpcomponents-core/blob/a5c117028b7c620974304636d52f06f172f1d08b/httpcore/src/main/java/org/apache/http/protocol/RequestContent.java#L102]


> Content-Length missing on null entity request content
> -----------------------------------------------------
>
>                 Key: HTTPCORE-759
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-759
>             Project: HttpComponents HttpCore
>          Issue Type: Improvement
>          Components: HttpCore
>    Affects Versions: 5.2.2
>            Reporter: Billy Jaime Beltran
>            Priority: Minor
>              Labels: easyfix
>
> 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|https://github.com/apache/httpcomponents-core/blob/e3c770b55602eb9e5a45dfe7c6a07a1adede2c95/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestContent.java#L106]
> 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|https://github.com/apache/httpcomponents-core/blob/a5c117028b7c620974304636d52f06f172f1d08b/httpcore/src/main/java/org/apache/http/protocol/RequestContent.java#L102]
>  
> A suggested fix: re-add the null check and set Content-Length to zero.



--
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