'Is there any way to set some headers in request interceptor based on the http protocol version after negotiation in httpClient
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.
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ok2c |
