[
https://issues.apache.org/jira/browse/HTTPCORE-643?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17169854#comment-17169854
]
Oleg Kalnichevski commented on HTTPCORE-643:
--------------------------------------------
bq. others may not be so lucky have a single place to quickly add
"content-length: 0" to all requests made through hc.
[~ckozak] It can be easily done with a request interceptor as a cross cutting
aspect for all message exchanges
{code:java}
CloseableHttpClient httpClient = HttpClientBuilder.create()
.addRequestInterceptorLast((request, entity, context) -> {
final String method = request.getMethod();
if ((Method.POST.isSame(method) || Method.PUT.isSame(method))
&& !request.containsHeader(HttpHeaders.CONTENT_LENGTH)
&& !request.containsHeader(HttpHeaders.TRANSFER_ENCODING)) {
request.addHeader(HttpHeaders.CONTENT_LENGTH, "0");
}
})
.build();
{code}
There is really no justification to creating a configuration nob for each and
every protocol deviation.
Oleg
> Add zero content-length to PUT and POST requests with no entity
> ---------------------------------------------------------------
>
> Key: HTTPCORE-643
> URL: https://issues.apache.org/jira/browse/HTTPCORE-643
> Project: HttpComponents HttpCore
> Issue Type: Improvement
> Affects Versions: 5.0.1
> Reporter: Carter Kozak
> Priority: Major
>
> [https://tools.ietf.org/html/rfc7230#section-3.3.2] states "A user agent
> SHOULD send a Content-Length in a request message when
> no Transfer-Encoding is sent and the request method defines a meaning
> for an enclosed payload body."
>
> I encountered a proxy that rejected both PUT and POST requests with no
> content-length and no body by returning a 411 "Length Required" status. I
> believe this is rare, and servers are expected to support requests with and
> without a defined content length and no body, but it would be helpful to add
> the content-length by default to avoid incompatibility.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]