简体   繁体   English

来自非修改 POST 请求的 304 响应

[英]304 response from a non modifying POST request

I am working on a POST HTTP API which does not modify or create any state on the server.我正在处理 POST HTTP API,它不会在服务器上修改或创建任何 state。 The API is implemented with method POST as it needs to accept multiple complex inputs which would not be possible using query parameters. API 是使用 POST 方法实现的,因为它需要接受多个复杂的输入,而使用查询参数是不可能的。

What is the correct response status to return in case of conditional check failures ( If-Match / If-None-Match ) for such read-only POST APIs, should it be 304 Not Modified or 412 Precondition Failed ?在这种只读 POST API 的条件检查失败( If-Match / If-None-Match )的情况下,返回的正确响应状态是什么,应该是304 Not Modified还是412 Precondition Failed

Note: This is an internal service API where the client is aware that it is a non modifying request.注意:这是一个内部服务 API,客户端知道这是一个非修改请求。

For a GET request, we would expect an If-None-Match header, which would normally produce a 200 response with an updated copy of the representation if the condition holds, and a 304 response when the precondition fails (meaning that the clients copy of the resource is already up to date).对于 GET 请求,我们期望 If-None-Match header,如果条件成立,它通常会产生 200 响应和表示的更新副本,当前提条件失败时产生 304 响应(意味着客户端副本资源已经是最新的)。

The semantics should be the same when we use POST in a read-only way.当我们以只读方式使用 POST 时,语义应该是相同的。 (Note that we are in a bit of an edge case here; a general purpose client won't normally know that this particular POST request is safe, and probably won't know which precondition headers to attach to the request. For instance, if you try to use an HTML form in a web browser to access this resource, you probably aren't going to get the conditional headers that you want.) (请注意,我们在这里有点边缘情况;通用客户端通常不会知道这个特定的 POST 请求是安全的,并且可能不知道将哪些前提条件标头附加到请求。例如,如果您尝试在 web 浏览器中使用 HTML 表单来访问此资源,您可能不会获得所需的条件标头。)

412 Precondition Failed is normally used when requesting a modification to the resource, in combination with an If-Match header. 412 Precondition Failed 通常在请求修改资源时使用,结合 If-Match header。

Reference: HTTP Semantics, section 13 .参考: HTTP 语义,第 13 节

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM