httpwg / http-core

Core HTTP Specifications
https://httpwg.org/http-core/
466 stars 43 forks source link

how to handle C-L for unknown methods #1095

Open reschke opened 2 years ago

reschke commented 2 years ago

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).

royfielding commented 2 years ago

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).

reschke commented 2 years ago

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.

royfielding commented 2 years ago

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.