[
https://issues.apache.org/jira/browse/HTTPCORE-643?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17169651#comment-17169651
]
Carter Kozak commented on HTTPCORE-643:
---------------------------------------
This is interesting, based on the RFC there's nothing that strictly disallows
bodies from requests using the GET method, however I think the quote that I
originally linked "and the request method defines a meaning for an enclosed
payload body" aligns with the sections in
[https://tools.ietf.org/html/rfc7231#section-4.3] describing GET and HEAD[2]
interestingly also DELETE[3] including "A payload within a (GET|HEAD|DELETE)
request message has no defined semantics".
The OPTIONS[4] and TRACE[5] sections goes as far to specify "A client MUST NOT
send a message body"
> If one wants {{Content-Length: 0}} header present in the request message one
> needs to enclose an entity with no content.
That's fair, it certainly worked in my scenario, others may not be so lucky
have a single place to quickly add "content-length: 0" to all requests made
through hc. There's a question around discoverability as well, if I implement
this feature default-off it's more likely most users will add a zero-length
payload instead of using the feature, in which case it may not really make
sense to implement. It looks like this is already the case in feign, for
example:
[https://github.com/OpenFeign/feign/blame/ae514aaf790c87804b245013044bd212d3786b92/httpclient/src/main/java/feign/httpclient/ApacheHttpClient.java#L146-L148]
> 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]