/
105.txt
536 lines (426 loc) · 32.6 KB
/
105.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
[3] [DFN[[CODE(HTTP)@en[[[Vary:]]]]]] [[ヘッダー]]は、[[内容折衝]]に用いた[[要求]]中の[[ヘッダー]]を示します。
[4] この[[ヘッダー]]は、同じ [[URL]] で出し分けされている複数の[[応答]]を[[キャッシュ]]で正しく処理するためのものです。
* 仕様書
[REFS[
- [2625] [CITE@en[RFC 7231 - Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content]] ([TIME[2014-08-07 05:54:02 +09:00]] 版) <https://tools.ietf.org/html/rfc7231#section-7.1.4>
]REFS]
* 意味
[2629] [CODE(HTTP)@en[[[Vary:]]]] [[ヘッダー]]は、
[[要求メッセージ]]の ([[要求メソッド]]、 [CODE(HTTP)@en[[[Host:]]]]、
[[要求対象]]以外の) どの部分が[[起源鯖]]における当該[[応答]]の選択と表現の処理に影響したかもしれないかを説明するものです
[SRC[>>2625]]。
* 文脈
[2638] [[起源鯖]]は、[[要求メソッド]]と[[要求対象]]以外の[[要求メッセージ]]の状況を元に異なる[[表現]]を選択している場合には、異なりを示せない場合や敢えて[[キャッシュ透過性]]を失くすよう設定されている場合を除き、
[CODE(HTTP)@en[[[Vary:]]]] [[ヘッダー]]を送信する[['''べきです''']]。 [SRC[>>2625]]
[EG[
[2639] 例えば [CODE(HTTP)@en[[[Authorization:]]]] [[ヘッダー]]は定義上別の[[利用者]]に[[応答]]を再利用できないと決められているので敢えて
[CODE(HTTP)@en[[[Vary:]]]] に示す必要はありません。 [SRC[>>2625]]
]EG]
;; [2640] [[起源鯖]]は、 [CODE(HTTP)@en[[[Vary:]]]] が[[キャッシュ]]に影響することによる性能の問題に比べると異なった[[表現]]の存在は重要ではないと考えるなら、
[CODE(HTTP)@en[[[Cache-Control:]]]] [[ヘッダー]]を使って制御できます。 [SRC[>>2625]]
[2645] [CODE(HTTP)@en[[[Vary:]]]] [[ヘッダー]]は複数指定できません。
;; [[HTTPヘッダー]>>443]
* 構文
[2630] 値は、 [CODE[[[*]]]] のみか、または1つ[[以上]]の[[ヘッダー名]]の[[リスト]] ([CODE[#]]) です。
[[ヘッダー名]]は[[大文字・小文字不区別]]です。 [SRC[>>2625]]
[FIG(railroad)[
= |
== [CODE[[[*]]]]
== =
=== [[ヘッダー名]]
=== *
==== [[OWS]]
==== [CODE[[[,]]]]
==== [[OWS]]
==== [[ヘッダー名]]
]FIG]
* [CODE[*]]
[2631] [CODE[[[*]]]] は[[要求]]の何かが[[応答]]の[[表現]]の選択に影響したかもしれないことを表します。影響した要素は[[メッセージ]]外の何か
(例えば[[クライアント]]の[[ネットワークアドレス]]) かもしれません。 [SRC[>>2625]]
[2632] [[受信者]]は、この[[応答]]を以後の[[要求]]に適切かどうかを、
[[要求]]を[[起源鯖]]に[[転送]]することなく決定はできません。 [SRC[>>2625]]
[2633] [[串]]は、 [CODE(HTTP)@en[[[Vary:]] [[*]]]] を[[生成]]しては[['''なりません''']]
[SRC[>>2625]]。
* ヘッダー名
[2634] [[ヘッダー名]]は、[RUBYB[選択に関わったヘッダー]@en[selecting header field]]、
すなわち[[表現]]の選択に関わったかもしれない[[ヘッダー]]を表します。 [SRC[>>2625]]
[2644] この[[ヘッダー名]]は、[[要求]]に明示されている[[ヘッダー]]の名前でなくても構いません。
ある[[ヘッダー]]が存在しないことが[[応答]]の[[表現]]の選択に関わったなら、
それを指定することができます。
[EG[
[2635] 例えば、
[PRE(HTTP code)[
Vary: accept-encoding, accept-language
]PRE]
... は、[[起源鯖]]が[[応答]]の[[表現]]を選ぶに当たり[[要求]]の
[CODE(HTTP)@en[[[Accept-Encoding:]]]] と [CODE(HTTP)@en[[[Accept-Language:]]]]
(あるいはその不存在) を考慮したかもしれないことを表しています [SRC[>>2625]]。
]EG]
* 処理モデル
[2636] [[キャッシュ]]の[[受信者]]は、指定された[[ヘッダー名]]が元の[[要求]]と同じでない限り、
以後の[[要求]]を満足するためにこの[[応答]]を使っては[['''なりません''']] [SRC[>>2625]]。
[2637] [[利用者エージェント]]の[[受信者]]は、 [CODE(HTTP)@en[[[Vary:]]]]
[[ヘッダー]]に[[ヘッダー名]]が指定されていることによりその[[応答]]が[[内容折衝]]の対象であると認識し、
指定されている[[ヘッダー]]に更に値を加える事で別の[[表現]]が得られるかもしれないと判断できます
([[proactive negotiation]])。 [SRC[>>2625]]
[2641] 実際のところ [[proactive negotiation]] は使われておらず、
[[利用者エージェント]]は一般に [CODE(HTTP)@en[[[Vary:]]]] [[ヘッダー]]を無視していると思われます。
理論上は[[利用者エージェント]]の[[キャッシュ]]でも区別が必要ですが、
実用上は同じ[[利用者エージェント]]で頻繁に [CODE(HTTP)@en[[[Accept:]]]]
や [CODE(HTTP)@en[[[Accept-Language:]]]] の値を変更することはありませんから、
問題とはならないはずです。
[2642] 実際には[[鯖]]が [CODE(HTTP)@en[[[Vary:]]]] [[ヘッダー]]を指定することや正しい内容を記載することは保証されていませんから、
これを信頼するのは難しいと思われます。例えば多くの[[Webアプリケーション]]が[[鯖]]側で
[CODE(HTTP)@en[[[User-Agent:]]]] による[[応答]]の出し分けを行っていますが、
[CODE(HTTP)@en[[[Vary:]] [[User-Agent]]]] を明示しないのが普通です。
[[共有キャッシュ]]のような任意の[[鯖]]に接続する[[串]]では、
[[URL]] と [CODE(HTTP)@en[[[Vary:]]]] のみによる[[キャッシュ]]の管理は実用的ではなさそうです。
[[著者]]側が構成を完全に管理可能な[[逆串]]型の[[キャッシュ]]であれば
[CODE(HTTP)@en[[[Vary:]]]] による[[キャッシュ]]の管理は可能で、実際に大規模な
[[Webアプリケーション]]のキャッシュのために用いられています。
;; [2643] ところで[[キャッシュ]]を行う[[串]]の中には [CODE(HTTP)@en[[[Vary:]]]]
に対応しておらず、[[対象資源]]の [[URL]] のみに基づくものもあります。
* 歴史
[5] [[RFC2068]] と [[RFC2616]] で、大体書いてある内容は同じなのに、かなり修正が加えてあって、段落の順序が行ったり来たりしていて比較するのに厄介です。
[SAMP[RFC [DEL(RFC2068)[2068]] [INS(RFC2616)[2616]]]] のようにして差分を分かりやすく書いたはずだったのですが、段落の移動とかのせいでぐちゃぐちゃで却って分かりにくくなったような気がしています。ごめんんさい。
順序は RFC 2616 base なので、削除部分を読み飛ばせば 2616
として読むことができます。
目視で差分取りつつ merge してるので、うっかり落とした単語とかがあるかもしれません。原文も併せて参照して下さい。
[FIG(quote)[
[FIGCAPTION[
[2626] RFC [DEL(RFC2068)[2068]] [INS(RFC2616)[2616]] (HTTP/1.1) 14.[DEL(RFC2068)[43]][INS(RFC2616)[44]] Vary
]FIGCAPTION]
[DEL[
>The Vary response-header field is used by a server to signal that the
response entity was selected from the available representations of
the response using server-driven negotiation (section 12).
Field-names listed in Vary headers are those of request-headers. The Vary
field value indicates either that the given set of header fields
encompass the dimensions over which the representation might vary, or
that the dimensions of variance are unspecified ("*") and thus may
vary over any aspect of future requests.
[1] [CODE(HTTP)[Vary]] [[応答頭欄]]は、[[鯖]]が、応答[[実体]]は[[サーバー駆動折衝]]を使って利用可能な応答の[[表現]]から選択したことを通知するために使います。
[CODE(HTTP)[Vary]] 頭欄に列挙される欄名は要求頭欄のものです。
[CODE(HTTP)[Vary]] 頭欄の値は、その頭欄の集合が表現が変化し得る範囲を含むことも、
変化の範囲が未指定 ([CODE(ABNF)["*"]])
で、従って将来の要求のどの角度によっても変化しうることをも示します。
]DEL]
[INS[
>The Vary field value indicates the set of request-header fields that
fully determines, while the response is fresh, whether a cache is
permitted to use the response to reply to a subsequent request
without revalidation. For uncacheable or stale responses, the Vary
field value advises the user agent about the criteria that were used
to select the representation. A Vary field value of "*" implies that
a cache cannot determine from the request headers of a subsequent
request whether this response is the appropriate representation. See
section 13.6 for use of the Vary header field by caches.
[11] [CODE(HTTP)[Vary]] 欄の値は、
キャッシュが、要求が新鮮な間において、
再検証すること無しにその応答を後続の要求に返信するのに使うことが認められるかを完全に決定する要求頭欄の集合を示します。
キャッシュ不能であるか、又は新鮮でない応答に対しては、
[CODE(HTTP)[Vary]] 欄の値は、
表現を選択するのに使われた基準を[[利用者エージェント]]に助言するものとなります。
[CODE(HTTP)[Vary]] 欄の値 [CODE(ABNF)["*"]] は、キャッシュが、
この応答が後続の要求に対して適切な表現であるかどうかをその要求頭だけから決定出来ないことを示します。
キャッシュの [CODE(HTTP)[Vary]]
頭欄の使用については13.6節 [INS[(>>17)]] をご覧下さい。
]INS]
-[12] [CODE(ABNF)[Vary = "Vary" ":" ( "*" | 1#field-name )]]
>An HTTP/1.1 server [DEL(RFC2068)[MUST]] [INS(RFC2616)[SHOULD]]
include a[DEL(RFC2068)[n appropriate]]
Vary header field with any
cacheable response that is subject to server-driven negotiation.
Doing so allows a cache to properly interpret future requests on that
resource and informs the user agent about the presence of negotiation
on that resource.
A server [DEL(RFC2068)[SHOULD]] [INS(RFC2616)[MAY]]
include a[DEL(RFC2068)[n appropriate]]
Vary header field with a
non-cacheable response that is subject to server-driven negotiation,
since this might provide the user agent with useful information about
the dimensions over which the
response [DEL(RFC2068)[might vary]] [INS(RFC2616)[varies at the time of the response]].
[13] [[HTTP/1.1]] サーバーは、サーバー駆動折衝の対象であるどんなキャッシュ可能な応答についても[DEL(RFC2068)[適切な]]
[CODE(HTTP)[Vary]] 頭欄を含め[DEL(RFC2068)[なければ'''なりません''']][INS(RFC2616)[る'''べきです''']]。
そうすることで、キャッシュが将来の要求を適切に解釈することが出来ますし、利用者エージェントにその資源についての折衝があったことを知らせることとなります。
サーバーは、サーバー駆動折衝の対象であるキャッシュ可能でない資源についても、[DEL(RFC2068)[適切な]]
[CODE(HTTP)[Vary]] 頭欄を含め[DEL(RFC2068)[る'''べきです''']][INS(RFC2616)[ても'''構いません''']]。
というのは、これによって、利用者エージェントに[DEL(RFC2068)[変化し得る]][INS(RFC2616)[応答の時点での応答の変種の]]規模についての有用な情報を提供することが出来るのです。
[INS[
(RFC 2068 では次は >>18)]]
(RFC 2068 では >>16 から次の段落に続く。)
]INS]
>A Vary field value consisting of a list of field-names signals that
the representation selected for the response is based on a selection
algorithm which considers ONLY the listed request-header field values
in selecting the most appropriate representation. A cache MAY assume
that the same selection will be made for future requests with the
same values for the listed field names, for the duration of time for
which the response is fresh.
[14] [CODE(HTTP)[Vary]] 欄の値は、欄名の一覧で構成します。
これは、最も適切な表現を選択するに当たって、
列挙された要求頭欄の値'''のみ'''を考慮する選択算法に基づいて、その応答の表現が選ばれたことを表します。
キャッシュは、応答が新鮮である時間内においては、
列挙された欄名に対して同じ値を持った将来の要求があった時に同じ選択がなされるものと仮定しても'''構いません'''。
>The field-names given are not limited to the set of standard
request-header fields defined by this specification. Field names are
case-insensitive.
[15] 与える欄名はこの仕様書 [INS[(RFC 2616)]]
で定義された標準の要求頭欄の集合には制限しません。
欄名は大文字・小文字を区別しません。
[INS[
(RFC 2068 では >>15 で 14.43 節は終わり。)
(RFC 2068 では >>20 から次の段落に続く。)
]INS]
>A Vary field value of "*" signals that unspecified parameters[DEL(RFC2068)[,]] [DEL(RFC2068)[possibly other than the contents of]] [INS(RFC2616)[not limited to the]] request-headers (e.g., the network address of the
client), play a role in the selection of the response representation. [DEL(RFC2068)[Subsequent requests on that resource can only be properly interpreted by the origin server, and thus a cache MUST forward a (possibly conditional) request even when it has a fresh response cached for the resource. See section 13.6 for use of the Vary header by caches.]] [INS(RFC2616)[The "*" value MUST NOT be generated by a proxy server; it may only be generated by an origin server.]]
[16] [CODE(HTTP)[Vary]] 欄の [CODE(ABNF)["*"]]
という値は、要求頭に限らない、記述されていない変数
(例えばクライアントのネットワーク・アドレス)
が応答の表現の選択に影響したことを表します。 [DEL(RFC2068)[この資源に対する後続の要求は、源サーバーによってのみ適切に解釈され得、従ってキャッシュは、その資源の新鮮な応答がキャッシュされていても、 (おそらく条件付で) 要求を転送しなければ'''なりません'''。]] [INS(RFC2616)[串サーバーは [CODE(ABNF)["*"]] という値を生成しては'''なりません'''。源サーバーのみがこの値を生成できます。]]
[INS[
(RFC 2068 では >>14 に続く)
]INS]
]FIG]
[FIG(quote)[
[FIGCAPTION[
[2627] RFC 2616 (HTTP/1.1) 13.6 Caching Negotiated Responses
]FIGCAPTION]
>Use of server-driven content negotiation (section 12[INS(RFC2616)[.1]]), as indicated
by the presence of a Vary header field in a response, alters the
conditions and procedure by which a cache can use the response for
subsequent requests. [INS(RFC2616)[See section 14.44 for use of the Vary header field by servers.]]
[17] サーバー駆動内容折衝を使用 (12[INS(RFC2616)[.1]]節)
することによって、 [CODE(HTTP)[Vary]]
頭欄が応答中に現れることで示される通り、
キャッシュが後続の要求に対してその応答を使用することで状態と手続きが変更されます。 [INS(RFC2616)[サーバーによる [CODE(HTTP)[Vary]] 頭欄の使用については 14.4 節 [INS[(>>11)]] をご覧下さい。]]
[DEL[
(RFC 2068 での >>17 の続き)
>A server MUST use the Vary header field (section 14.43) to inform a
cache of what header field dimensions are used to select among
multiple representations of a cachable response. A cache may use the
selected representation (the entity included with that particular
response) for replying to subsequent requests on that resource only
when the subsequent requests have the same or equivalent values for
all header fields specified in the Vary response-header. Requests
with a different value for one or more of those header fields would
be forwarded toward the origin server.
>If an entity tag was assigned to the representation, the forwarded
request SHOULD be conditional and include the entity tags in an If-
None-Match header field from all its cache entries for the Request-
URI. This conveys to the server the set of entities currently held by
the cache, so that if any one of these entities matches the requested
entity, the server can use the ETag header in its 304 (Not Modified)
response to tell the cache which entry is appropriate. If the
entity-tag of the new response matches that of an existing entry, the
new response SHOULD be used to update the header fields of the
existing entry, and the result MUST be returned to the client.
>The Vary header field may also inform the cache that the
representation was selected using criteria not limited to the
request-headers; in this case, a cache MUST NOT use the response in a
reply to a subsequent request unless the cache relays the new request
to the origin server in a conditional request and the server responds
with 304 (Not Modified), including an entity tag or Content-Location
that indicates which entity should be used.
(>>23 に続く。)
]DEL]
[INS[
(RFC 2068 では >>13 の後が次の段落。)
]INS]
>[INS(RFC2616)[A server SHOULD use the Vary header field to inform a cache of what request-header fields were used to select among multiple representations of a cacheable response subject to server-driven negotiation.]] The set of header fields named by the Vary field value
is known as the "selecting" request-headers.
[18] [INS(RFC2616)[サーバーは、サーバー駆動折衝の対象であってキャッシュ可能な応答の複数の表現から選ぶのにどの要求頭欄が使われたかをキャッシュに告げるために、 [CODE(HTTP)[Vary]] 頭欄を使用する'''のが良い'''です。]]
[CODE(HTTP)[Vary]] 欄の値に挙げられた頭欄の集合は
「選択」要求頭とも呼ばれます。
>When the cache receives a subsequent request whose Request-URI
specifies one or more cache entries including a Vary header [INS(RFC2616)[field]],
the cache MUST NOT use such a cache entry to construct a response to
the new request unless all of the [INS(RFC2616)[selecting request-]]headers [DEL(RFC2068)[named in the cached Vary header are]] present
in the new request [INS(RFC2616)[match the corresponding stored request-headers in
the original request]].
[19] [CODE(ABNF)[Request-URI]] が [CODE(HTTP)[Vary]]
頭[INS(RFC2616)[欄]]を含むキャッシュ項目を1つ以上指定している後続の要求をキャッシュが受信した時は、
キャッシュは新しい要求にある全ての[DEL(RFC2068)[キャッシュされた [CODE(HTTP)[Vary]] 頭に名前が挙げられた]][INS(RFC2616)[選択要求]]頭が[DEL(RFC2068)[出現する]][INS(RFC2616)[保管している元の要求の対応する要求頭と一致する]]ので無い限り、
新しい要求への応答を構築するのにそのようなキャッシュ項目を使っては'''なりません'''。
>The selecting request-headers from two requests are defined to match
if and only if the selecting request-headers in the first request can
be transformed to the selecting request-headers in the second request
by adding or removing linear white space (LWS) at places where this
is allowed by the corresponding BNF, and/or combining multiple
message-header fields with the same field name following the rules
about message headers in section 4.2.
[20] 二番目の要求の選択頭欄を、相当する BNF
で許されている箇所に置いて線形空白間隔 (LWS)
を追加したり削除したりすること[[及び/又は]]4.2節のメッセージ頭についての規則に従って同じ欄名の複数のメッセージ頭欄を結合することによって、最初の要求の選択頭欄に変形できる場合、
この場合に限って、2つの要求の選択要求頭は[DNF[一致する]]と定義します。
[INS[
(RFC 2068 では >>16 に続く)
]INS]
>A Vary header field-value of "*" always fails to match and subsequent
requests on that resource can only be properly interpreted by the
origin server.
[21] [CODE(HTTP)[Vary]] 頭欄の値が [CODE(ABNF)["*"]] の時には、
その資源への後続の要求は源サーバーによってのみ適切に解釈出来るので、
絶対に一致しません。
>If the selecting request header fields for the cached entry do not
match the selecting request header fields of the new request, then
the cache MUST NOT use a cached entry to satisfy the request unless
it first relays the new request to the origin server in a conditional
request and the server responds with 304 (Not Modified), including an
entity tag or Content-Location that indicates the entity to be used.
[22] 新しい要求の選択要求頭欄がキャッシュされている項目の選択要求頭欄が一致しなければ、
キャッシュはその要求を満足させるのにキャッシュされた項目を使っては'''なりません'''。
但し、最初に新しい要求を源サーバーに条件付要求で中継して、
使用される実態を示す[[実体札]]又は [CODE(HTTP)[Content-Location]]
を含んだ [CODE(HTTP)[304]] (未修正)
のサーバー応答を受け取った場合を除きます。
>If an entity tag was assigned to a cached representation, the
forwarded request SHOULD be conditional and include the entity tags
in an If-None-Match header field from all its cache entries for the
resource. This conveys to the server the set of entities currently
held by the cache, so that if any one of these entities matches the
requested entity, the server can use the ETag header field in its 304
(Not Modified) response to tell the cache which entry is appropriate.
If the entity-tag of the new response matches that of an existing
entry, the new response SHOULD be used to update the header fields of
the existing entry, and the result MUST be returned to the client.
[23] キャッシュされた表現に実体札が割当てられていたなら、
転送する要求は条件付として、その資源のキャッシュ項目全ての実体札を
[CODE(HTTP)[If-None-Match]] 頭欄に含める'''べきです'''。
これによってサーバーに現在キャッシュが保持している実体の集合を伝えることが出来て、
その実体のいずれかが要求された実体と一致していれば、サーバーは
[CODE(HTTP)[[[304]]]] (無修正) 応答に [CODE(HTTP)[ETag]]
頭欄を使用することでキャッシュのどの実体が適切か教えることが出来ます。
新しい応答の実体札が既存の項目と一致したなら、
新しい応答は既存の項目の頭欄を更新するのに使う'''べき'''で、
その結果はクライアントに返さなければ'''なりません'''。
>If any of the existing cache entries contains only partial content
for the associated entity, its entity-tag SHOULD NOT be included in
the If-None-Match header [INS(RFC2616)[field]] unless the request is for a range that
would be fully satisfied by that entry.
[24] 既存のキャッシュ項目のいずれかが関連付けられた実体の部分内容のみしか含んでいなければ、
その要求がその項目で十分満足される範囲に対するものでない限りは、
その実体札を [CODE(HTTP)[If-None-Match]] 頭[INS(RFC2616)[欄]]に含める'''べきではありません'''。
>If a cache receives a successful response whose Content-Location
field matches that of an existing cache entry for the same
Request-URI, whose entity-tag differs from that of the existing entry, and
whose Date is more recent than that of the existing entry, the
existing entry SHOULD NOT be returned in response to future requests
and SHOULD be deleted from the cache.
[25] キャッシュが成功応答を受け取り、その
[CODE(HTTP)[Content-Location]] 欄が同じ [CODE(ABNF)[Request-URI]]
に対する既存のキャッシュ項目のものと一致し、
その実体札は既存の項目のものとは異なるもので、
[CODE(HTTP)[Date]] は既存の項目のものより最近であるのなら、
既存の項目は将来の要求の応答として返す'''べきではなく'''、
キャッシュから削除する'''べきです'''。
]FIG]
[FIG(quote)[
[FIGCAPTION[
[2628] RFC 2295 (HTTP 透過内容折衝) 10.6 Elaborate Vary headers
]FIGCAPTION]
[32]
> If a HTTP/1.1 [1] server can generate varying responses for a request
on some resource, then the server MUST include a Vary header in these
responses if they are cacheable. This Vary header is a signal to
HTTP/1.1 caches that something special is going on. It prevents the
caches from returning the currently chosen response for every future request on the resource.
HTTP/1.1 サーバーがなんかの資源に対する要求で変化する応答を生成することができるときは、
サーバーはその応答が[[キャッシュ可能]]であれば
[CODE(HTTP)[[[Vary]]]] 頭を含めなければ'''なりません'''。
この [CODE(HTTP)[Vary]] 頭は HTTP/1.1 キャッシュに何か特別なことをしているのだと通知します。
これによってキャッシュが現在選ばれた応答をその資源についての将来の要求に返さないようにします。
> Servers engaging in transparent content negotiation will generate
varying responses. Therefore, cacheable list, choice, and adhoc
responses MUST always include a Vary header.
> The most simple Vary header which can be included is
- Vary: *
> This header leaves the way in which the response is selected by the
server completely unspecified.
> A more elaborate Vary header MAY be used to allow for certain
optimizations in HTTP/1.1 caches which do not have specific
optimizations for transparent content negotiation, but which do cache
multiple variant responses for one resource. Such a more elaborate
Vary header lists all request headers which can be used by the server
when selecting a response for a request on the resource.
より詳細な [CODE(HTTP)[Vary]] 頭を使用して透過内容折衝には特に最適化しないけれども一つの資源についての複数の変種資源はキャッシュする
HTTP/1.1 キャッシュでの最適化を可能にしても'''構いません'''。
そのようなより詳細な [CODE(HTTP)[Vary]] 頭は、サーバーがその資源についての要求に対する応答を選択するときに使用することが出来るすべての要求頭を列挙します。
* 10.6.1 Construction of an elaborate Vary header
> Origin servers can construct a more elaborate Vary header in the
following way. First, start with the header
起源サーバーは次の方法でより詳細な [CODE(HTTP)[Vary]]
頭欄を構築できます。まず、頭
>
- Vary: negotiate
> `negotiate' is always included because servers use the information in
the Negotiate header when choosing between a list, choice, or adhoc response.
から始めます。 [CODE(HTTP)[negotiate]] はサーバーが[[目録応答]]・[[選択応答]]・[[臨時応答]]を選ぶときに
[CODE(HTTP)[[[Negotiate]]]] 頭の情報を使用するので、
常に含みます。
> Then, if any of the following attributes is present in any variant
description in the Alternates header, add the corresponding header
name to the Vary header
それから、 [CODE(HTTP)[[[Alternates]]]] 頭の[[変種記述]]のいずれかに次の属性のどれかが示されていれば、
対応する頭名を [CODE(HTTP)[Vary]] 頭に追加します。
>
[PRE[
attribute | header name to add
-----------+---------------------
type | accept
charset | accept-charset
language | accept-language
features | accept-features
]PRE]
> The Vary header constructed in this way specifies the response
variation which can be caused by the use of a variant selection
algorithm in proxies. If the origin server will in some cases, for
example if contacted by a non-negotiating user agent, use a custom
negotiation algorithm which takes additional headers into account,
these names of these headers SHOULD also be added to the Vary header.
この方法で構築された [CODE(HTTP)[Vary]] 頭は串で変種選択算法を使用したときに起こり得る応答変種を指定します。
起源サーバーが、例えば非折衝利用者エージェントにより接触を受けた場合など幾つかの場合では、
追加の頭を考慮に入れた個別折衝算法を使用するのであれば、
その頭の名前も [CODE(HTTP)[Vary]] 頭に追加する'''べきです'''。
*10.6.2 Caching of an elaborate Vary header
> A proxy cache cannot construct an elaborate vary header using the
method above, because this method requires exact knowledge of any
custom algorithms present in the origin server. However, when
extracting an Alternates header from a response (section 10.4) caches
MAY also extract the Vary header in the response, and reuse it along
with the Alternates header. A clean Vary header can however only be
extracted if the variant does not vary itself, i.e. if a Variant-Vary header is absent.
前述の方法は起源サーバーでどんな個別算法を使ったかの正確な知識が必要となるので、
この方法を使って串キャッシュが詳細な変化頭を構築することは出来ません。
しかし、応答から [CODE(HTTP)[Alternates]] 頭を取り出すときには、
キャッシュは応答から [CODE(HTTP)[Vary]]
頭をも取り出して、 [CODE(HTTP)[Alternates]] 頭と一緒に再利用しても'''構いません'''。
しかし、綺麗な [CODE(HTTP)[Vary]] 頭を取り出すことが出来るのは、
変種自体が変化しない時、つまり [CODE(HTTP)[[[Variant-Vary]]]]
頭がないときだけです。
]FIG]
[26] RFC 2616 は [CODE(HTTP)[Vary:]] 欄の値になるものを[[要求頭欄]]に限定していますが、[[一般頭欄]]や[[実体頭欄]]では駄目なのでしょうか? あんまり普通じゃないだけで、別にいいですよね、そう限定しなくても。
[2617] [CITE@en[RFC 3143 - Known HTTP Proxy/Caching Problems]] ([TIME[2008-08-30 12:43:01 +09:00]] 版) <http://tools.ietf.org/html/rfc3143#section-2.1.1>
[2619] [CITE[Apache HTTP Server Project]]
( ([TIME[2011-05-28 00:58:55 +09:00]] 版))
<http://httpd.apache.org/docs/1.3/misc/known_client_problems.html#ie40-vary>
* 統計
[2618] [CITE@en[HTTP/1.1 Vary header]] ([TIME[2009-07-19 11:40:34 +09:00]] 版) <http://www.http-stats.com/Vary>
*メモ
[27] [[Apache]] なんかは折衝をしたら [CODE(HTTP)[[[negotiate]]]] という謎の値を必ず送るんで、なんなのかなあと思うんですが、なんなんでしょう? 実質的に [CODE(HTTP)[*]] と同じ意味になるわけですが。
[31] >>27 HTTP 本体の仕様書だけ読んでると確かにそう思ってしまうのですが、 [[RFC2295]] で [[Negotiate:]] という欄が規定されています。折衝時の [CODE(HTTP)[Vary:]] 欄の使い方についても言及があるので、ぜひ読んでおきましょう。
- [28] >>12 の構文だと、 [SAMP(HTTP)[Vary: [VAR[foo]]]] と別の欄で [SAMP(HTTP)[Vary: [VAR[bar]]]] にすることが出来ない (欄の値全体が [CODE(ABNF)[#]] で定義されてはいないため。) のですが、ちょっとまずくありません?
[33] 言語を折衝したときに [CODE(HTTP)[[[Content-Langage]]]] を [CODE(HTTP)[Vary]] に加えると間違って解説しているところがありますが、正しくは [CODE(HTTP)[''Accept''-Language]] を加える、です。クライアントからの受入れ言語申告に基づき折衝するのですから。[WEAK[クライアントからの実体の言語に基づき折衝するという稀な場合は [CODE(HTTP)[Content-Language]] で正しいですが、そんな場面ってあるでしょうか?]]
[2620] [CITE@en[Building Smartphone-Optimized Websites - Webmasters — Google Developers]]
([TIME[2012-06-07 02:56:13 +09:00]] 版)
<https://developers.google.com/webmasters/smartphone-sites/details>
[2621] [CITE@en[Re: ''''''[''''''XHR'''''']'''''' Open issue: allow setting User-Agent?]]
( ([[Boris Zbarsky]] 著, [TIME[2012-10-17 02:08:59 +09:00]] 版))
<http://lists.w3.org/Archives/Public/public-webapps/2012OctDec/0200.html>
[2622] [CITE@en[HTTP - WHATWG Wiki]]
( ([TIME[2012-11-08 09:54:29 +09:00]] 版))
<http://wiki.whatwg.org/wiki/HTTP#Assume_Vary:_User-Agent>
[2623] [CITE[CORS and caches explained · fb04b72 · whatwg/fetch]]
( ([TIME[2014-05-21 03:26:24 +09:00]] 版))
<https://github.com/whatwg/fetch/commit/fb04b72c54fc14d487184c6716a0b0f15832d5c2>