[ https://issues.apache.org/jira/browse/HTTPCLIENT-2382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18006718#comment-18006718 ]
Oleg Kalnichevski commented on HTTPCLIENT-2382: ----------------------------------------------- [~anasquazbary] HttpClient of all versions _DOES NOT_ remove any request headers explicitly set by the caller by default, _ever_. if Content-Length or Transfer-Encoding has been explicitly set by the caller HttpClient will refuse to execute the request [1]. One must explicitly configure HttpClient to relax this restriction. I have no idea what http4k-client-apache is and what it does. Please reproduce the problem with HttpClient 5.5 without any extra layers on top of it. Otherwise I will have to close this issue as invalid. Oleg [1] https://github.com/apache/httpcomponents-core/blob/master/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestContent.java#L107 > Apache HttpClient removes the `Content-Length` header from a DELETE request > even when the request has a body and the header is explicitly set. > ---------------------------------------------------------------------------------------------------------------------------------------------- > > Key: HTTPCLIENT-2382 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2382 > Project: HttpComponents HttpClient > Issue Type: Bug > Components: HttpClient (classic) > Reporter: Anas Quazbary > Priority: Trivial > Fix For: 5.3.1 > > > _(Usage via http4k-client-apache 5.29.0.0 with Apache HttpClient 5.3.1)_ > When using Apache HttpClient (via http4k in Kotlin), I noticed that the > {{Content-Length}} header is removed from DELETE requests, even when: > * a body is explicitly set, and > * the header is manually added to the request. > As a result, the request is rejected or mishandled by the server expecting > the header (e.g., visible via ngrok). > *To Reproduce* > Steps to reproduce the behavior: > # Create a {{DELETE}} request with a JSON body and explicitly set the > {{Content-Length}} header. > # Send it using Apache HttpClient (via http4k). > # Observe the outgoing request (e.g., via ngrok or a proxy). > # {{Content-Length}} is missing. > kotlin : > {code:java} > val request = Request(Method.DELETE, "https://xxx.ngrok.io") > .header("Content-Type", "application/json") > .header("Content-Length", "16") > .body("""{"some": "data"}""")val client = ApacheClient() > val response = client(request) {code} > *Expected behavior:* > Either: > Apache HttpClient should honor manually set Content-Length when a body is > present, > or automatically compute and include it when a body is given, even for DELETE > requests. > Thank you for your time and assistance. Please let me know if you need any > additional information to help diagnose this issue. -- 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