实体列表的 HTTP 范围标头

发布于 2024-12-11 14:55:58 字数 845 浏览 0 评论 0原文

我有这样的资源

/entities        # GET, POST
/entities/<id>   # GET, PUT, DELETE

GET /entities 获取所有实体的列表。 现在我想轮询更新。单个实体的情况很简单:

GET /entities/2
If-Modified-Since: <http date>

该列表很棘手。我希望响应是自给定时间点以来更新或创建的实体列表。我直观地使用

GET /entities
Range: after <http date>

这是 HTTP 规范的有效请求 http://www.w3 .org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2 。但规范还强制要求 206 Partial Content 响应,其中必须包含 Content-Range 标头。 Content-Range 标头又要求指定字节范围http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16 。这对于我的用例来说显然非常不方便。

您将如何通过 HTTP 请求语义范围?

I have resources like this

/entities        # GET, POST
/entities/<id>   # GET, PUT, DELETE

GET /entities gets the list of all entities.
Now I want to poll for updates. The case for a single entity is straight forward:

GET /entities/2
If-Modified-Since: <http date>

The list is tricky. I want the response to be a list of entities, updated or created since a given point in time. I'd intuitively use

GET /entities
Range: after <http date>

Which is a valid request by HTTP specification http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2 . But the spec also mandates a 206 Partial Content response, which has to include a Content-Range header. A Content-Range header, in turn, mandates a byte range to be specified http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16 . This is obviously very inconvenient for my use case.

How would you request a semantic range over HTTP?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆梦 2024-12-18 14:55:58

从阅读 14.35.1 部分,我会说Range 标头用于从资源请求特定范围的字节,而不是根据修改时间请求一组实体。

在这种情况下,我认为您应该将范围视为过滤器并将日期作为查询字符串参数传递:

GET /entities?modified-since=<date>

From reading section 14.35.1, I would say that the Range header is used to request a specific range of bytes from a resource, not to request a group of entities according to when they were modified.

In this case, I believe you should treat your range as a filter and pass the date as a query string parameter:

GET /entities?modified-since=<date>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文