/
490.txt
231 lines (181 loc) · 11.9 KB
/
490.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
[410] [DFN[[CODE(HTTP)@en[[[Accept-Encoding:]]]]]] [[ヘッダー]]は、
[[利用者エージェント]]が受け入れ可能な[[内容符号化]]を[[鯖]]に対して示すものです。
* 仕様書
[REFS[
- [409] [CITE@en[RFC 7231 - Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content]] ([TIME[2014-06-07 01:55:45 +09:00]] 版) <https://tools.ietf.org/html/rfc7231#section-5.3.4>
]REFS]
* 意味
[411] [CODE(HTTP)@en[[[Accept-Encoding:]]]] [[ヘッダー]]は、
[[応答]]においてどの[[内容符号化]]が受け入れ可能かを[[利用者エージェント]]が示すものです
[SRC[>>409]]。
[418] [CODE(HTTP)@en[[[Accept-Encoding:]]]] なしの[[要求]]は、
[[利用者エージェント]]が[[内容符号化]]について特に好みが無いことを表します [SRC[>>409]]。
* 文脈
[412] 複数の[[ヘッダー]]を指定することもできます。
* 構文
[413] [[欄値]]は、0個以上の値の[[リスト]] ([CODE[#]]) です [SRC[>>409]]。
[FIG(railroad)[
= ?
== 符号化と重み
== *
=== [[OWS]]
=== [CODE[[[,]]]]
=== [[OWS]]
=== 符号化と重み
]FIG]
[414] [[リスト]]のそれぞれの値は、符号化の名前か、その後に [CODE(HTTP)@en[[[q]]]]
[[引数]]を指定したものです [SRC[>>409]]。
[415] 符号化の名前は、[[内容符号化]]の名前か、 [CODE(HTTP)@en[[[identity]]]] か、
[CODE(HTTP)[[[*]]]] のいずれかです [SRC[>>409]]。
[FIG(railroad)[
= |
== [[字句]]
== [CODE[[[*]]]]
= ?
== [[OWS]]
== [CODE[[[,]]]]
== [[OWS]]
== |
=== [CODE[[[q]]]]
=== [CODE[[[Q]]]]
== [CODE[[[=]]]]
== [[品質値]]
]FIG]
[424] [CODE(HTTP)@en[[[Accept-Encoding:]]]] [[ヘッダー]]がいずれも空なら、
どの[[内容符号化]]も望まないことを示しています [SRC[>>409]]。
;; [425] [CODE(HTTP)@en[[[identity]]]] のみ指定した場合と同じになります。
;; [427] ほとんどの [[HTTP/1.0]] [[応用]]は、
[[内容符号化]]の [CODE(HTTP)@en[[[q]]]]
に対応していません [SRC[>>409]]。
* [CODE(HTTP)[*]]
[416] [CODE(HTTP)@en[[[Accept-Encoding:]]]] [[ヘッダー]]における [CODE(HTTP)@en[[[*]]]]
は、他に明記されていないすべての利用可能な[[内容符号化]]を表します [SRC[>>409]]。
;; [417] [[内容符号化]]、とされていますが、 [CODE(HTTP)@en[[[identity]]]]
も含まれるようです (>>421)。
* 処理モデル
[419] [[鯖]]は、ある[[表現]]で適用されている[[内容符号化]]が受け入れられるかどうか、
次のようにして決定します [SRC[>>409]]。
[FIG(steps)[
= [420] [CODE(HTTP)@en[[[Accept-Encoding:]]]] [[ヘッダー]]がなければ、
どの[[内容符号化]]も受け入れられると考えます。
= [421] 当該[[表現]]が[[内容符号化]]無しなら、
[CODE(HTTP)@en[[[identity]];[[q]]=0]] が指定されている場合や
[CODE(HTTP)@en[[[identity]]]] の指定なしで [CODE(HTTP)@en[*;[[q]]=0]]
が指定されている場合を除き、受け入れられます。
= [422] 当該[[表現]]の[[内容符号化]]が [CODE(HTTP)@en[[[Accept-Encoding:]]]]
に指定されているもののいずれかであるなら、 [CODE(HTTP)[[[q]]=0]]
が指定されている場合を除き、受け入れられます。
]FIG]
[423] 複数の[[内容符号化]]が受け入れられる場合は、
[CODE(HTTP)[[[q]]]] が最高の値のものを優先します [SRC[>>409]]。
[426] [[期限鯖]]は、受け入れられる[[内容符号化]]がなければ、
[[内容符号化]]なしの[[応答]]を送る[['''べきです''']] [SRC[>>409]]。
* 歴史
[REFS[
- [407] [CITE[Request Headers in the HTTP protocol]]
( ([TIME[2001-11-29 11:01:38 +09:00]] 版))
<http://www.w3.org/Protocols/HTTP/HTRQ_Headers.html#accept-encoding>
]REFS]
[1] 古い時代の [[HTTP]] では (他の欄同様に) [CODE(HTTP)[[[,]]]] と [CODE(HTTP)[[[;]]]] を逆に使ったりすることもありました。
[2] というかそうしていました。
[FIG(quote)[
[FIGCAPTION[
[408] RFC 1945 (HTTP/1.0) D.2.3; RFC 2068・2616 (HTTP/1.1) 14.3 Accept-Encoding
]FIGCAPTION]
> The Accept-Encoding request-header field is similar to Accept, but restricts the [DEL[[INS[{1945,2068}]] content-coding values [INS[[INS[{2068}]] (section 14.12)]] which]] [INS[[INS[{2616}]] content-codings (section 3.5) that]]
are acceptable in the response.
[CODE(HTTP)[Accept-Encoding]] 応答頭欄は、 [CODE(HTTP)[[[Accept]]]]
と同様のものですが、応答で受入れ可能な [[content-coding]] を制限します。
[INS[
> [INS[{2068,2616}]]
- [DEL[[INS[{2068}]] [CODE(ABNF)[[DFN[Accept-Encoding]] = "Accept-Encoding" ":" #( content-coding )]]]]
- [INS[[INS[{2616}]] [CODE(ABNF)[[DFN[Accept-Encoding]] = "Accept-Encoding" ":" 1#( codings [ ";" "q" "=" qvalue ] )]]]]
- [INS[[INS[{2616}]] [CODE(ABNF)[[DFN[codings]] = ( content-coding | "*" )]]]]
> [DEL[[INS[{2068}]] An example of its use is]] [INS[[INS[{2616}]] Examples of its use are:]]
- Accept-Encoding: compress, gzip
- [INS[[INS[{2616}]] Accept-Encoding:]]
- [INS[[INS[{2616}]] Accept-Encoding: *]]
- [INS[[INS[{2616}]] Accept-Encoding: compress;q=0.5, gzip;q=1.0]]
- [INS[[INS[{2616}]] Accept-Encoding: gzip;q=1.0, identity; q=0.5, *;q=0]]
[INS[
> [INS[{2616}]] A server tests whether a content-coding is acceptable, according to
an Accept-Encoding field, using these rules:
= 1. If the content-coding is one of the content-codings listed in
the Accept-Encoding field, then it is acceptable, unless it is
accompanied by a qvalue of 0. (As defined in section 3.9, a
qvalue of 0 means "not acceptable.")
= 2. The special "*" symbol in an Accept-Encoding field matches any
available content-coding not explicitly listed in the header field.
= 3. If multiple content-codings are acceptable, then the acceptable
content-coding with the highest non-zero qvalue is preferred.
= 4. The "identity" content-coding is always acceptable, unless
specifically refused because the Accept-Encoding field includes
"identity;q=0", or because the field includes "*;q=0" and does
not explicitly include the "identity" content-coding. If the
Accept-Encoding field-value is empty, then only the "identity"
encoding is acceptable.
サーバーは、 [CODE(HTTP)[Accept-Encoding]] 欄に従い、次の規則を使って
[CODE(ABNF)[content-coding]] が受け入れ可能かを検査します:
= Content-coding が [CODE(HTTP)[Accept-Encoding]] 欄に列挙された content-coding
なら、その [[qvalue]] が [CODE(HTTP)[0]] でない限りは受入れ可能です。
(3.9 節で定義したように、 qvalue [CODE(HTTP)[0]] は「受入れ不能」を意味します。)
= [CODE(HTTP)[Accept-Encoding]] 欄中の特殊な [CODE(HTTP)[*]] 記号は、
頭欄中に陽に列挙されていない利用可能な content-coding に一致します。
= 複数の content-coding が受入れ可能なら、最高の非零 qvalue の受入れ可能
content-coding を優先します。
= [CODE(HTTP)[[[identity]] content-coding は、 [CODE(HTTP)[Accept-Encoding]] 欄が]]
[CODE(HTTP)[identity;q=0]] を含むか、 [CODE(HTTP)[*;q=0]]
を含んで [CODE(HTTP)[identity]] content-coding を陽に含んでいないために特に断られていない限り、
常に受入れ可能です。 [CODE(HTTP)[Accept-Encoding]] 欄値が空の場合、
[CODE(HTTP)[identity]] 符号化だけが受入れ可能です。
> If an Accept-Encoding field is present in a request, and if the
server cannot send a response which is acceptable according to the
Accept-Encoding header, then the server SHOULD send an error response
with the 406 (Not Acceptable) status code.
[CODE(HTTP)[Accept-Encoding]] 欄が要求に示されている場合、
そしてサーバーが [CODE(HTTP)[Accept-Encoding]] 頭に従って受入れ可能な応答を送れない場合は、
サーバーは [CODE(HTTP)[[[406]]]] (受入れ不能) 状態符号で誤り応答を送る'''べきです'''。
]INS]
> If no Accept-Encoding field is present in a request, the server MAY
assume that the client will accept any content coding. [INS[[INS[{2616}]] In this case, if "identity" is one of the available content-codings, then the server SHOULD use the "identity" content-coding, unless it has additional information that a different content-coding is meaningful to the client.]] [DEL[[INS[{2068}]] If an Accept-Encoding header is present, and if the server cannot send a response which is acceptable according to the Accept-Encoding header, then the server SHOULD send an error response with the 406 (Not Acceptable) status code.]]
[CODE(HTTP)[Accept-Encoding]] 欄が要求中に示されていない場合、
サーバーはクライアントがどの内容符号かも受け入れると仮定しても'''構いません'''。 [INS[[INS[{2616}]] この場合、 [CODE(HTTP)[identity]] が利用可能な content-coding の1つであれば、クライアントにはこれ以外の content-coding に意味があるという追加の情報がない限り、サーバーは [CODE(HTTP)[identity]] content-coding を使用する'''べきです'''。]] [DEL[[INS[{2068}]] [CODE(HTTP)[Accept-Encoding]] 頭が示されている場合、そしてサーバーが [CODE(HTTP)[Accept-Encoding]] 頭に従って受入れ可能な応答を送れない場合は、サーバーは [CODE(HTTP)[[[406]]]] (受入れ不能) 状態符号で誤り応答を送る'''べきです'''。]]
[DEL[
> [INS[{2068}]] An empty Accept-Encoding value indicates none are acceptable.
空の [CODE(HTTP)[Accept-Encoding]] 値は、どれも受け入れ可能でないことを示します。
]DEL]
[INS[
> [INS[{2616}]] Note: If the request does not include an Accept-Encoding field,
and if the "identity" content-coding is unavailable, then
content-codings commonly understood by HTTP/1.0 clients (i.e.,
"gzip" and "compress") are preferred; some older clients
improperly display messages sent with other content-codings. The
server might also make this decision based on information about
the particular user-agent or client.
> Note: Most HTTP/1.0 applications do not recognize or obey qvalues
associated with content-codings. This means that qvalues will not
work and are not permitted with x-gzip or x-compress.
注意 : 要求が [CODE(HTTP)[Acceot-Encoding]] 欄を含んでいない場合、
そして [CODE(HTTP)[identity]] content-coding が利用可能で無い場合、
HTTP/1.0 クライアントが広く理解可能な content-coding
(すなわち [CODE(HTTP)[[[gzip]]]] 及び [CODE(HTTP)[[[compress]]]])
が優先されます。幾つかの古いクライアントは他の content-coding
で送られたメッセージを不適切に表示します。サーバーは特定の利用者エージェントまたはクライアントについての情報にも基づいてこの決定を行うかもしれません。
注意 : ほとんどの HTTP/1.1 応用は content-coding
に関連付けられた qvalue を認識したり従ったりしません。
これは、 qvalue が [CODE(HTTP)[[[x-gzip]] や [CODE(HTTP)[[[x-compress]]]]]]
では働かず、認められないことを意味します。
]INS]
]INS]
]FIG]
* 実装
[3] 今の時代の [[UA]] でも、知らない content-coding
を使ってるとそのまま表示しちゃったりしますよね。。。
[4]
[CODE(HTTP)@en[[[Accept-Encoding]]]] を受信したら[[鯖]]はそれに従うか
[CODE(HTTP)@en[[[406]]]] と[['''するべきです''']]と [[RFC 2616]]
にはありますが、実際の多くの [[Web頁]]ではそうはならないようです。
例えば、 [CODE(HTTP)@en[[[Accept-Encoding]]: [[*]]; [[q]]=0]]
とだけあれば必ず [CODE(HTTP)@en[[[406]]]] が返されるべきですが、
実際にそうなるのは [[Apache]] で[[内容折衝]]が用いられている静的な[[文書]]などに限られます。
([[名無しさん]] [WEAK[2007-11-23 05:49:34 +00:00]])