If-None-Match 有效时 304 Not Modified有效、Match、None、If

2023-09-07 10:43:46 作者:给涐旳敷衍不停旳重演

我正在优化一个 Express JSON API 以供 iOS &Android 应用程序,并且当应用程序在 If-None-Match 标头中指定 etag 时,似乎无法让 Express 以正确的 304 标头响应.

I am optimizing an Express JSON API for consumption by iOS & Android Apps and do not seem to be able to get Express to respond with the correct 304 header when the Apps specify an etag within the If-None-Match header.

我不需要设置 Etag 生成,因为 Express 已经提供了这些;但是,当应用程序在第二个请求中再次指定该 etag 时;Express 的响应仍然是 200 的数据,正如您在 Postman 中的测试中看到的那样:

I needn't setup Etag generation as Express was already providing those; however when the Apps specify that etag again in a second request; Express' response is still a 200 with the data, as you can see in my tests in Postman:

如何启用此功能?

更新:iOS 开发人员从 Express 服务器看到正确的 304 Not Modified 响应,但我不明白为什么我在 Postman 中没有看到它们 - Postman 是否支持此类操作?p>

Update: The iOS dev is seeing the correct 304 Not Modified responses from the Express server but I don't understand why I am not seeing them within Postman - Does Postman support such actions?

推荐答案

我今天偶然发现这个,你需要禁用 Postman 默认发送 Cache-Controlnone.为此,只需将设置将 Send no-cache header 更改为 No.

I just stumble across this today, you need to disable Postman default behaviour of sending Cache-Control as none. To do this just go to settings change Send no-cache header to No.