如何将ETAG正确发送回HTTP IF-NONE匹配请求标头的Web服务器?
我正在尝试使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
etag
,的语法,
if-none-match ,以及与条件请求有关的其他标题,在 rfc 7232 。从那里可以看出,有效的
etag
需要双引号:因此您提到的第一个示例无效。
如果不匹配
应该只是逗号分隔的Entity-tags
(或*
)的系列,包括双引号和任何弱者指标。 包括a 几个示例:该标准 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:So the first example you mentioned is invalid.
If-None-Match
should just be a comma-separated series ofentity-tags
(or*
), including the double quotes and any weak indicators. The standard includes a few examples:So: send the
ETag
back the same way you received it.