I have a use case where I have to send content-length in the request header for only http2 calls. After setting content-length for all calls, in case of http1.1, it is throwing below exception, Caused by: org.apache.hc.core5.http.ProtocolException: Content-Length header already present at org.apache.hc.core5.http.protocol.RequestContent.process(RequestContent.java:103)

Even after adding the last request interceptor to add length-content at last level, It is throwing same exception looks like the last interceptor is not the last interceptor.

I have also tied to put some protocol version based check but again the version it tells is incorrect, says http1.1 thought actually it is http2.

I am using httpclient5 library.

1

There are 1 best solutions below

1
On

Unfortunately HttpClient 5.1 fails to set the negotiated HTTP protocol version in the execution context correctly due to HTTPCLIENT-2200 [1]. The issue will be resolved in upcoming HttpClient 5.2-beta1.

For now use a custom header (X-Content-Length) for all protocol versions.

[1] https://issues.apache.org/jira/browse/HTTPCLIENT-2200