25

次のシナリオを検討してください。

  • 記事のリストを返す RESTful URL /articles があります
  • ユーザーは、各リクエストで Authorization HTTP ヘッダーを使用して資格情報を提供します
  • 記事は、権限に基づいてユーザーごとに異なる場合があります

このシナリオで Squid などのキャッシング プロキシを使用することは可能ですか? プロキシは URL /articles のみを参照するため、キャッシュを生成した最初のユーザーに対してのみ有効な記事のリストを返す場合があります。URL /articles を要求している他のユーザーは、アクセス権のない記事を見ることができますが、これはもちろん望ましくありません。

独自のキャッシュをロールバックする必要がありますか、それとも一部のキャッシング プロキシ ソフトウェアを構成して、Authorization HTTP ヘッダーに基づいてキャッシュを作成できますか?

4

2 に答える 2

29

試してみる 1 つの可能性は、応答ヘッダーを使用して、要求のヘッダーVary: Authorizationに基づいてキャッシュされたドキュメントを変更することにより、キャッシュに注意するように下流のキャッシュに指示することです。Authorization

response-compression を使用している場合は、既にこのヘッダーを使用している可能性があります。ユーザーは通常、ヘッダー付きのリソースを要求しますAccept-Encoding: gzip, deflate。サーバーが圧縮をサポートするように構成されている場合、応答にはヘッダーが含まれている可能性がありContent-Encoding: gzipますVary: Accept-Encoding

于 2009-11-09T13:48:06.913 に答える
11

HTTP/1.1 RFC セクション 14.8 ( https://www.rfc-editor.org/rfc/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.
于 2014-08-26T08:50:08.887 に答える