gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 15:27:16 26 4
gpt4 key购买 nike

来自 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 是唯一包含验证器 header 部分的动词(请参阅 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 来向用户代理指示表示是否已更改。

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

如果表示已更改,则根据定义,用户代理的表示无效。因此不会返回任何验证器 header ,用户代理将不得不执行无条件的 GET

关于rest - 为什么对 PUT 请求的响应不能提供 ETag?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42246577/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com