请考虑以下情况:
在这种情况下,可以像Squid一样使用缓存代理吗? 代理只会看到URL /文章,因此它可能会返回仅对生成缓存的第一个用户有效的文章列表。请求URL /文章的其他用户可以看到他们无权访问的文章,当然这是不可取的。
我应该滚动自己的缓存还是可以配置一些缓存代理软件以将其缓存基于授权HTTP标头?
答案 0 :(得分:29)
尝试的一种可能性是使用Vary: Authorization
响应标头指示下游缓存通过根据请求的Authorization
标头更改缓存文档来注意缓存。
如果使用响应压缩,则可能已在使用此标头。用户通常请求具有标题Accept-Encoding: gzip, deflate
的资源;如果服务器配置为支持压缩,则响应可能会随标题Content-Encoding: gzip
和Vary: Accept-Encoding
一起提供。
答案 1 :(得分:10)
通过HTTP / 1.1 RFC第14.8节(http://tools.ietf.org/html/rfc2616#section-14.8):
When a shared cache (see section 13.7) receives a request
containing an Authorization field, it MUST NOT return the
corresponding response as a reply to any other request, unless one
of the following specific exceptions holds:
1. If the response includes the "s-maxage" cache-control
directive, the cache MAY use that response in replying to a
subsequent request. But (if the specified maximum age has
passed) a proxy cache MUST first revalidate it with the origin
server, using the request-headers from the new request to allow
the origin server to authenticate the new request. (This is the
defined behavior for s-maxage.) If the response includes "s-
maxage=0", the proxy MUST always revalidate it before re-using
it.
2. If the response includes the "must-revalidate" cache-control
directive, the cache MAY use that response in replying to a
subsequent request. But if the response is stale, all caches
MUST first revalidate it with the origin server, using the
request-headers from the new request to allow the origin server
to authenticate the new request.
3. If the response includes the "public" cache-control directive,
it MAY be returned in reply to any subsequent request.