为什么对 PUT 请求的响应不能提供 ETag?

Why responses to PUT requests MUST NOT provide an ETag?

来自 Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content:

An origin server MUST NOT send a validator header field (Section 7.2), such as an ETag or Last-Modified field, in a successful response to PUT unless the request's representation data was saved without any transformation applied to the body (i.e., the resource's new representation data is identical to the representation data received in the PUT request) and the validator field value reflects the new representation. This requirement allows a user agent to know when the representation body it has in memory remains current as a result of the PUT, thus not in need of being retrieved again from the origin server, and that the new validator(s) received in the response can be used for future conditional requests in order to prevent accidental overwrites (Section 5.2).

我不能完全理解这部分... 加粗的句子似乎自相矛盾,不是吗?

请注意,PUT 是唯一包含验证器 headers 部分的动词(参见 GET/POST/DELETE/PATCH)。

关键是服务器可能会也可能不会在存储之前更改表示。从您链接到的部分:

A successful PUT of a given representation would suggest that a subsequent GET on that same target resource will result in an equivalent representation being sent in a 200 (OK) response. However, there is no guarantee that such a state change will be observable, since the target... might be subject to dynamic processing by the origin server.

因此,该标准使用是否存在验证器 header 来向用户代理指示表示是否已更改。

如果表示没有被更改,那么服务器可以 return 验证器 header 字段,用户代理可以使用它有条件地验证它刚刚发送的表示。

如果表示已更改,则根据定义,用户代理的表示无效。因此,没有验证器 header 被 return 编辑,用户代理将不得不执行无条件的 GET.