nginx 与弱 etag 不匹配

问题描述 投票:0回答:1

背景:
当客户端发送

Accept-Encoding: gzip
时,nginx 会生成弱 etag https://twitter.com/samsaffron/status/486387129165942784

我正在使用 reangular 来调用端点
Restangular 接收弱 etag 并将其发送到

if-None-Match
标头中,而不对 etag 进行任何修改
https://github.com/mgonto/restangular/blob/d55c4392b184e659c11f50e225d64c3a04da6572/src/restangular.js#L588
但是 nginx 不会将 etag 与它在
if-None-Match
中收到的内容相匹配, 它将发送
200 OK
http 响应,而它应该发送
304 Not Modified
http 响应。
邮递员:

如果我在

if-None-Match
标头中将 etag 作为强 etag 发送(条带
W/
),nginx 将发送 304 响应。
邮递员:

如何解决这个问题?
当它作为

W/
发送时,是否应该从 etag 中删除
if-None-Match

MDN 说 W/ 不需要发送
if-None-Match

may be prefixed by `W/` to indicate that the weak comparison algorithm should be used (This is useless with If-None-Match as it only uses that algorithm).
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Match

或者即使是弱etag nginx也应该能够匹配吗?

nginx 版本1.13.3

nginx restangular etags
1个回答
0
投票

我遇到了同样的问题,在发送回刚刚发送给我的 If-None-Match 中的弱 etag 时,从 nginx 收到了 200 OK(和正文)! nginx 1.7.3 中添加了较弱的 etag 支持,所以它应该可以工作。

问题(经过一番绞尽脑汁)原来是本地操作系统缓存(由 macOS 的 NSURLConnection 使用),它用 200 OK 代替了 304 Not Modified。检查 nginx 日志显示它实际上响应了 304,并且没有发送任何正文,正如它应该的那样。

这可能不是你的问题,但这个问题与我的搜索相匹配,所以我将这个答案留在这里,以防它帮助其他人以后走同样的路:)

© www.soinside.com 2019 - 2024. All rights reserved.