If-None-Match与多个实体有什么用途? [英] What are the uses for If-None-Match with multiple entities?

查看:191
本文介绍了If-None-Match与多个实体有什么用途?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ETag 标头进行缓存,浏览器会发送相应的 If-None-Match 标头。最初,我只是简单地比较了这些标题,但它确实有效。



后来我发现 rfc2616 允许实体列表,所以我修复了它。问题是,如果修复程序被使用...




  • 浏览器是否发出了带有的请求If-None-Match 包含多个实体的标头?

  • 还有其他现实世界吗?


解决方案

我可以想到两个用例:浏览器和缓存代理实体标签的联合以及自定义客户端缓存实现。 / p>

虽然我从未见过浏览器在 If-None-Match 中提供多个实体标签的请求,但是有缓存代理可能拥有自己所请求资源的版本。它们可以替换浏览器发送的 If-None-Match 的值与浏览器的资源版本实体标签和代理资源版本实体标签的联合,然后再发送请求服务器。这样,如果代理具有所请求资源的新版本,则可以通过从代理而不是服务器提供完整响应(使用正文有效负载)来减少服务器负载。此案例由 RFC 7234超文本传输​​协议(HTTP / 1.1)描述:缓存


当缓存决定为包含If-None-的
请求重新验证其自己存储的响应时匹配实体标签列表,缓存
可以将收到的列表与来自其自己的
存储的响应集(新鲜或陈旧)的实体标签列表组合,并发送$ b $的并集b两个列表作为
转发请求中的替换If-None-Match头字段值。


我不能说是否支持RFC 7234的那部分是广泛的,但肯定有代理支持它。查看Colin Mollenhour的 Node.js缓存反向HTTP代理项目。



另一方面,您可能不希望依赖浏览器来执行条件请求。您可以使用 XMLHttpRequest.setRequestHeader()自行设置 If-None-Match HTTP标头值。如果使用 Web Storage API存储多个版本的资源,这将非常有用缓存API 或其他机制。服务器响应必须包含带有entity-tag的 ETag HTTP标头。此实体标记指示资源的哪个版本被视为新鲜。


I'm using the ETag header for caching and the browser sends a corresponding If-None-Match header. Initially, I simply compared these headers and it worked.

Later it occurred to me that rfc2616 allows a list of entities, so I fixed it. The question is, if the fix gets ever used...

  • Does the browser ever issue a request with an If-None-Match header containing more than one entity?
  • Are there any other real world uses?

解决方案

There are two use cases that I can think of: union of browser and caching proxy entity-tags and custom client-side cache implemenation.

Although, I never seen browser serves request with multiple entity-tags in If-None-Match, there are caching proxies that may have it's own version of a requested resource. They may replace value of If-None-Match sent by browser with union of browser's resource version entity-tag and proxy resource version(s) entity-tag before sending request further to server. This way if proxy has fresh version of a requested resource you can reduce server load by serving full response (with body payload) from proxy instead of a server. This case is described by RFC 7234 Hypertext Transfer Protocol (HTTP/1.1): Caching:

When a cache decides to revalidate its own stored responses for a request that contains an If-None-Match list of entity-tags, the cache MAY combine the received list with a list of entity-tags from its own stored set of responses (fresh or stale) and send the union of the two lists as a replacement If-None-Match header field value in the forwarded request.

I can't say whether support of that part of RFC 7234 is wide, but certainly there are proxies that support it. Check Node.js Caching Reverse HTTP Proxy project by Colin Mollenhour.

On the other hand you may not want to rely on browser to perform conditional request. You can set If-None-Match HTTP header value by yourself using XMLHttpRequest.setRequestHeader(). This can be useful if you store multiple versions of a resource using Web Storage API, Cache API or other mechanism. Server response must contain ETag HTTP header with entity-tag. This entity-tag indicates which version of a resource is considered fresh.

这篇关于If-None-Match与多个实体有什么用途?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆