我正在阅读 HTTP basic authentication .在 MDN 网站上,它说:
Because BA header has to be sent with each HTTP request, the web browser needs to cache the credentials for a reasonable period to avoid constant prompting user for the username and password. Caching policy differs between browsers. Microsoft Internet Explorer by default caches them for 15 minutes.
但是,在我告诉chrome postman之后发送没有缓存 header 的请求 当我在服务器端记录流量时,我仍然注意到存在 authorization
字段:
{ host: 'localhost:3000',
connection: 'keep-alive',
authorization: 'Basic YWRtaW46cGFzc3dvcmQ=', // why?
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36',
'cache-control': 'no-cache',
'postman-token': '7e458c2d-b11b-026d-809b-68a7cf3d5a37',
....
然后我也尝试只使用 google chrome,但我再次看到了 authorization
字段:
{ host: 'localhost:3000',
connection: 'keep-alive',
pragma: 'no-cache',
'cache-control': 'no-cache',
authorization: 'Basic YWRtaW46cGFzc3dvcmQ=', // again
....
问题 1:我为 Chrome 都禁用了缓存(我找不到no-cached 选项,所以我选择了“禁用缓存” 在 chrome 调试器中)和 postman(它有一个“无缓存 header ”选项),但它们仍然包含 authentication
header ...为什么?我怎样才能阻止他们这样做?
问题 2:当我试图让客户端不发回Cookie时,同样的事情发生了,我什至使用了clear cookie chrome 历史记录中的功能......但我仍然在请求 header 中看到它的存在。我假设每个 header 字段的缓存方式不同,那么我该如何管理 cookie?
打开隐身窗口将使浏览器忘记授权和 cookie...但只有一次:后续选项卡将具有这些 header 。
最佳答案
我也注意到了同样的事情,这令人沮丧。但是您可以点击 Chrome 网络检查器中的“禁用缓存”选项,它将/应该将其删除(在我的情况下,我只需要它来使用新的 Auth header 更新缓存)。
不过这很令人担忧,因为如果用户登录应用程序并且 token 过期,应用程序可以刷新它并将新 token 提供给 http 客户端,但 Chrome 会自动用过期 token 覆盖它...
关于google-chrome - 如何禁用 http header 的缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37558074/