问题描述
当服务器为异步请求返回 202 - Accepted
状态码时,估计请求完成的适当方法是什么?
What is the appropriate way of giving an estimate for request completion when the server returns a 202 - Accepted
status code for asynchronous requests?
来自 HTTP 规范(我添加的斜体):
202 接受
请求已被接受处理,但处理尚未完成.[...]
The request has been accepted for processing, but the processing has not been completed. [...]
与此响应一起返回的实体应包含请求当前状态的指示以及指向状态监视器的指针或用户可以期望何时完成请求的一些估计.p>
The entity returned with this response SHOULD include an indication of the request's current status and either a pointer to a status monitor or some estimate of when the user can expect the request to be fulfilled.
以下是一些想法:
- 我看过 max-age指令,但使用它会滥用
Cache-Control
? - 在响应正文中返回预期的等待时间?
- 添加特定于应用程序的
X-
响应标头,但 ? - 添加(非
X-
)特定响应标头?如果是这样,它应该如何命名?SO问题 Custom HTTP headers : Naming conventions 给出了一些想法,但在弃用之后它只回答了 HTTP 标头的格式,而不是它们应该如何命名. - 其他建议?
- I have glanced at the max-age directive, but using it would be abusing
Cache-Control
? - Return the expected wait time in the response body?
- Add an application specific
X-
response header, but theX-
headers was deprecated in RFC 6648? - Add a (non
X-
) specific response header? If so, how should it be named? The SO question Custom HTTP headers : naming conventions gave some ideas, but after the deprecation it only answers how HTTP headers are formatted, not how they should be named. - Other suggestions?
推荐答案
虽然没有明确提到 202 - Accepted
响应代码,但 Retry-After
标头似乎成为一个合适的选择.来自文档:
Although not explicitly mentioned specifically for the 202 - Accepted
response code, the Retry-After
header seems to be a suitable option. From the documentation:
Retry-After response-header 字段可用于 [...] 来指示服务预计对请求客户端不可用的时间.
这篇关于HTTP 状态 202 - 如何提供有关异步请求完成的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!