← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 2962.b.8

条件写保护资源版本

理解等级:高级

条件写是在修改前核对资源版本,防止旧快照覆盖他人新修改。创建固定URL资源时用If-None-Match: *;更新时把先前取得的ETag放入If-Match。前提不成立就拒绝本次写入。

发生版本冲突后,要重新GET并结合最新内容调整修改,不能无条件覆盖。若前次请求已经成功、只是响应丢失,原条件重发可能被拒绝,客户端仍需核查实际状态;这与[[幂等写应区分丢响应]]并不矛盾。书中部分报文混写ETag/If-Match、412短语,本文保留其条件写机制,不把示例逐字当协议规范。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 分布式数据 · 查看原书依据

      When using HTTP PUT to update an existing data resource, the API client should send the If-Match: "…" header with the value set to the Etag header received when reading the record to update. This will make sure that the PUT will only be completed when the entity tags (ETag in the response and If-Match in the request) are the same.

    参考来源

    - 位置:《RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)》第6章《分布式数据》§6.2(来源项目:book-sources;源文件:extracted/RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)/_epub-src/OEBPS/ch06.xhtml) - 结论依据:原文以条件写是在修改前核对资源版本,防止旧快照覆盖他人新修改的方式说明该用途;同节示例与讨论补充了卡内条件和边界。 - 原始内容:When using HTTP PUT to update an existing data resource, the API client should send the If-Match: "…" header with the value set to the Etag header received when reading the record to update. This will make sure that the PUT will only be completed when the entity tags (ETag in the response and If-Match in the request) are the same.