如何将ETAG正确发送回HTTP IF-NONE匹配请求标头的Web服务器?

发布于 2025-02-05 02:33:21 字数 750 浏览 3 评论 0原文

我正在尝试使用HTTP最后修饰和ETAG标头正确使用缓存。据我所知,Web服务器以三种格式之一发送了一个ETAG:

  • 标准ETAG,例如waul9rdkgmuefoa7zlpa/vjx3ak
  • double-Quotes中的标准ETAG,例如gzip“
  • 弱eTag,例如w/“ 17ba-wxsgp4exobk6hgg6hgg35iod+5mrwq”

当我向同一URL发送新的http请求时,我可以发送header if code> if code>如果不确-match:< cached etag>,它将导致服务器在没有更改的情况下发送304请求。

我是否应该从ETAG中删除引号并将其发送以正确匹配?例如,如果标准ETAG为“ A8EF0-5B8E443CF07BA-GZIP”,我是否应该发送if-none-match:“ a8ef0-5b8e4443cf07ba-gzip”如果不匹配:A8EF0-5B8E443CF07BA-GZIP

同样,在开始时,我应该在开始时删除W/,以及引号,以便如果弱ETAG为w/“ 17ba-WXSGP4EAXOBKK6HGG6HGG35IOD+5MRWQ”> ,我发送一个的标题,如果没有匹配:17BA-WXSGP4EAXOBK6HGG35IOD+5MRWQ

I'm trying to use caching correctly using HTTP Last-Modified and Etag headers. From what I can see, web servers send back an Etag with one of 3 formats:

  • A standard Etag, e.g. wAUL9rDkgMueFoa7ZLPa/Vjx3ak
  • A standard Etag in double-quotes, e.g. "a8ef0-5b8e443cf07ba-gzip"
  • A weak Etag, e.g. W/"17ba-WxSGP4eaXoBk6hGG35IOD+5mrwQ"

When I send a new HTTP request for the same URL, I can send a header If-None-Match: <cached etag> which will cause the server to send a 304 request if it hasn't changed.

Should I remove the quotes from an Etag and send that, in order to match properly? For instance, if a standard Etag is "a8ef0-5b8e443cf07ba-gzip", should I send If-None-Match: "a8ef0-5b8e443cf07ba-gzip" or If-None-Match: a8ef0-5b8e443cf07ba-gzip?

Similarly, with a weak Etag should I remove the W/ at the beginning and also the quotes, so that if the weak etag is W/"17ba-WxSGP4eaXoBk6hGG35IOD+5mrwQ", I send a header of If-None-Match: 17ba-WxSGP4eaXoBk6hGG35IOD+5mrwQ?

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

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

发布评论

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

评论(1

魄砕の薆 2025-02-12 02:33:22

etag的语法, if-none-match ,以及与条件请求有关的其他标题,在 rfc 7232

从那里可以看出,有效的etag需要双引号:

ETag = entity-tag
entity-tag = [ weak ] opaque-tag
opaque-tag = DQUOTE *etagc DQUOTE

因此您提到的第一个示例无效。

如果不匹配应该只是逗号分隔的Entity-tags(或*)的系列,包括双引号和任何弱者指标。 包括a 几个示例

If-None-Match: "xyzzy"
If-None-Match: W/"xyzzy"
If-None-Match: "xyzzy", "r2d2xxxx", "c3piozzzz"
If-None-Match: W/"xyzzy", W/"r2d2xxxx", W/"c3piozzzz"
If-None-Match: *

该标准 ETAG 以您收到的方式返回。

The syntax for ETag, If-None-Match, and other headers related to conditional requests is defined in RFC 7232.

As can be seen there, a valid ETag requires double quotes:

ETag = entity-tag
entity-tag = [ weak ] opaque-tag
opaque-tag = DQUOTE *etagc DQUOTE

So the first example you mentioned is invalid.

If-None-Match should just be a comma-separated series of entity-tags (or *), including the double quotes and any weak indicators. The standard includes a few examples:

If-None-Match: "xyzzy"
If-None-Match: W/"xyzzy"
If-None-Match: "xyzzy", "r2d2xxxx", "c3piozzzz"
If-None-Match: W/"xyzzy", W/"r2d2xxxx", W/"c3piozzzz"
If-None-Match: *

So: send the ETag back the same way you received it.

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