http-core icon indicating copy to clipboard operation
http-core copied to clipboard

how to handle C-L for unknown methods

Open reschke opened this issue 3 years ago • 3 comments

https://httpwg.org/specs/rfc9110.html#field.content-length has:

A user agent SHOULD send Content-Length in a request when the method defines a meaning for enclosed content and it is not sending Transfer-Encoding. For example, a user agent normally sends Content-Length in a POST request even when the value is 0 (indicating empty content). A user agent SHOULD NOT send a Content-Length header field when the request message does not contain content and the method semantics do not anticipate such data.

I don't see how a sender can implement the "SHOULD NOT" correctly unless it happens to know the semantics of the method (which may not be the case for newly introduced methods).

reschke avatar Sep 15 '22 09:09 reschke

A user agent is expected to understand the semantics of any method it chooses to use, even if it is acting on downloaded instructions (e.g., javascript).

royfielding avatar Sep 15 '22 21:09 royfielding

But what does this mean, for instance, for an HTTP client library? How is it supposed to know? Are you saying that the program that uses the library needs to tell the library?

See https://github.com/openjdk/jdk/pull/8017 and https://github.com/apache/httpcomponents-core/pull/360.

reschke avatar Sep 16 '22 05:09 reschke

The person programming the library has to know and incorporate that into the code or calling parameters that implement a request and process the response. IOW, they deliberately choose to send content (or not) and the client has to send the correct header fields for that choice. The UA is the code calling the HTTP client library. A client library that allows arbitrary method construction just needs to know the difference (provide an API that distinguishes) between "no content" and "content of length 0". E.g., null versus empty string.

royfielding avatar Sep 16 '22 15:09 royfielding