-
Notifications
You must be signed in to change notification settings - Fork 4
/
376.txt
476 lines (356 loc) · 27.1 KB
/
376.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
[43] [DFN[[CODE(HTTP)@en[[[Content-Length:]]]]]] [[ヘッダー]]は、
[[メッセージ本体]]の長さを表します。
* 仕様書
[REFS[
- [38] [CITE@en[RFC 7230 - Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing]] ([TIME[2014-06-07 01:59:35 +09:00]] 版) <https://tools.ietf.org/html/rfc7230#section-3.3>
-- [44] [CITE@en[RFC 7230 - Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing]] ([TIME[2014-06-07 01:59:35 +09:00]] 版) <https://tools.ietf.org/html/rfc7230#section-3.3.2>
-- [312] [CITE@en[RFC 7230 - Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing]] ([TIME[2014-06-07 01:59:35 +09:00]] 版) <https://tools.ietf.org/html/rfc7230#section-3.3.3>
- [314] [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-4.3.6>
- [206] [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-4.3.7>
]REFS]
* 意味
[45] [CODE(HTTP)@en[[[Content-Length:]]]] [[ヘッダー]]は、
[CODE(HTTP)@en[[[Transfer-Encoding:]]]] [[ヘッダー]]のない[[メッセージ]]において
[[payload body]] のサイズを表すことができます [SRC[>>44]]。
これは [[payload body]] を含む[[メッセージ]]においては[[メッセージ]]の終端の位置を表す[[フレーム付け]]情報として必要なものであり、
[[payload body]] を含まない[[メッセージ]]においては選択された[[表現]]のサイズを示すものです
[SRC[>>44]]。
[39] [[要求メッセージ]]は通常[[メッセージ本体]]を持ちませんが、
[CODE(HTTP)@en[[[Content-Length:]]]] がある場合は[[メッセージ本体]]を持ちます [SRC[>>38]]。
;; [40] [[要求メソッド]]には依存しません。
* 文脈
[47] [[送信者]]は、 [CODE(HTTP)@en[[[Transfer-Encoding:]]]] [[ヘッダー]]がある[[メッセージ]]に
[CODE(HTTP)@en[[[Content-Length:]]]] [[ヘッダー]]を含めては[['''なりません''']] [SRC[>>44]]。
両方がある時は、 [CODE(HTTP)@en[[[Transfer-Encoding:]]]]
が優先されます [SRC[>>38 3.3.3.]]。[[送信者]]は[[転送]]前に [CODE(HTTP)@en[[[Content-Length:]]]]
を削除しなければ[['''なりません''']] [SRC[>>38 3.3.3.]]。
[313] [[利用者エージェント]]は、[[メッセージ本体]]付きの[[要求]]を送る場合、
[[鯖]]が [[HTTP/1.1]] に対応していると分かっている場合を除き、
[CODE(HTTP)@en[[[Content-Length:]]]] を送らなければ[['''なりません''']] [SRC[>>312]]。
[48] [[利用者エージェント]]は、[[要求メソッド]]が [[payload body]]
の意味を定義している場合には、 [CODE(HTTP)@en[[[Transfer-Encoding:]]]]
か [CODE(HTTP)@en[[[Content-Length:]]]] を送る[['''べきです''']] [SRC[>>44]]。
[[要求メソッド]]が [[payload body]] の意味を定義しておらず、[[メッセージ]]が
[[payload body]] を含んでいない場合には、
[CODE(HTTP)@en[[[Content-Length:]]]] を送る[['''べきではありません''']]
[SRC[>>44]]。
[306] [[起源鯖]]は、 [CODE(HTTP)@en[[[Transfer-Encoding:]]]]
を使用しない場合、事前に [[payload size]] が分かっているなら、
以降に示す場合を除き、 [CODE(HTTP)@en[[[Content-Length:]]]]
[[ヘッダー]]を送信する[['''べきです''']] [SRC[>>44]]。
[214] [[鯖]]は、 [CODE(HTTP)@en[[[OPTIONS]]]] に対する[[応答]]に [[payload body]] を含まない場合、
[CODE(HTTP)@en[[[Content-Length]]: 0]] を[[生成]]しなければ[['''なりません''']] [SRC[>>206]]。
[50] [[鯖]]は、 [CODE(HTTP)@en[[[HEAD]]]] [[要求]]に対する[[応答]]に
[CODE(HTTP)@en[[[Content-Length:]]]] [[ヘッダー]]を含めて構いませんが、
その場合 [CODE(HTTP)@en[[[GET]]]] だったなら返される[[応答]]で送られることになる
[[payload body]] のサイズを表すものでなければ[['''なりません''']] [SRC[>>44]]。
;; [53] [[キャッシュ]]における[[蓄積された応答]]の更新に使われます。
[CODE(HTTP)@en[[[HEAD]]]] を参照。
[51] [[鯖]]は、[[条件付GET]]に対する [CODE(HTTP)[[[304]]]] [[応答]]に
[CODE(HTTP)@en[[[Content-Length:]]]] [[ヘッダー]]を含めて構いませんが、
その場合 [CODE(HTTP)[[[200]]]] だったなら返される[[応答]]で送られることになる
[[payload body]] のサイズを表すものでなければ[['''なりません''']] [SRC[>>44]]。
[305] [[鯖]]は、 [CODE(HTTP)[[[1xx]]]] [[応答]]、[CODE(HTTP)[[[204]]]]
[[応答]]に [CODE(HTTP)@en[[[Content-Length:]]]] [[ヘッダー]]を含めては[['''なりません''']]
[SRC[>>44]]。
[311] [[鯖]]は、 [CODE(HTTP)@en[[[CONNECT]]]] [[要求]]に対する [CODE(HTTP)[[[2xx]]]]
[[応答]]に [CODE(HTTP)@en[[[Content-Length:]]]] [[ヘッダー]]を含めては[['''なりません''']]
[SRC[>>44, >>314]]。 [CODE(HTTP)@en[[[Content-Length:]]]] [[ヘッダー]]があっても、
無視しなければなりません [SRC[>>38 3.3.3., >>314]]。
* 構文
[46] 1桁以上の[[ASCII数字]]です [SRC[>>44]]。[[オクテット]]単位の[[十進数]]と解釈されます
[SRC[>>44]]。
;; [49] [[メッセージ本体]]が空の時は、 [CODE[0]] となります。
* 構文解析
[307] [[受信者]]は、大きな数値が指定される場合もありますから、
[[桁溢れ]]による構文解析エラーを防がなければ[['''なりません''']] [SRC[>>44]]。
[308] [CODE(HTTP)@en[[[Content-Length:]]]] [[ヘッダー]]が複数指定された場合や[[ヘッダー]]の値が[[リスト]]である場合で、
いずれも同じ十進数値の時は、この[[メッセージ]]を[[非妥当]]であるとして拒絶するか、
[CODE(HTTP)@en[[[Content-Length:]]]] [[ヘッダー]]1つで数値1つに置き換えてから解釈したり、
[[転送]]したりするかのいずれかとしなければ[['''なりません''']] [SRC[>>44]]。
[309] [CODE(HTTP)@en[[[Content-Length:]]]] [[ヘッダー]]が無視されない場合で、
複数指定されていて値が異なる場合や、値が[[非妥当]]な場合は、
[[接続]]を閉じなければ[['''なりません''']] [SRC[>>312]]。
* 処理モデル
[310] [[メッセージ本体]]の長さの決定方法は、 [[メッセージ本体]]の項を参照してください。
[52] [[メッセージ本体]]が指定された長さに満たない場合については、
[[不完全メッセージ]]を参照してください。
* メタ変数 [CODE(CGI)@en[CONTENT_LENGTH]] (CGI)
[8] [[CGI]] の[[メタ変数]] [DFN[[CODE(CGI)@en[[[CONTENT_LENGTH]]]]]] の値は、
[[要求]]に付随する[RUBYB[[[メッセージ本体]]]@en[message-body]]のサイズです [SRC[>>20]]。
** 仕様書
[REFS[
- [20] [CITE@en[RFC 3875 - The Common Gateway Interface (CGI) Version 1.1]] ([TIME[2011-11-20 06:09:05 +09:00]] 版) <http://tools.ietf.org/html/rfc3875#section-4.1.2>
]REFS]
** 値
[4] [[要求]]に[[メッセージ本体]]が存在している場合、その場合に限り、[[鯖]]は [CODE(CGI)@en[[[CONTENT_LENGTH]]]]
[[メタ変数]]を設定しなければ[['''なりません''']] [SRC[>>20]]。
[21] 値は[[メッセージ本体]]のサイズを[[オクテット]]単位の[[十進数]]で表したものです [SRC[>>20]]。
[24] サイズは[[鯖]]が[[転送符号化]]や[[内容符号化]]を除去した後の[[メッセージ本体]]の長さでなければなりません
[SRC[>>20]]。
;; [25] [[転送符号化]]だけでなく[[内容符号化]]も必要に応じて除去しなければならないのですね。
([[要求データ]]の項を参照。)
[22] [[メッセージ本体]]が付属していない場合は値は [[NULL]] ([[空文字列]] or 未設定) です [SRC[>>20]]。
[FIG[
[23]
[PRE(ABNF code)[
CONTENT_LENGTH = "" | 1*digit
]PRE]
[FIGCAPTION[
[SRC[>>20]]
]FIGCAPTION]
]FIG]
** メモ
[27] [[HTTP]] によりますと HTTP 通信においては [[Content-Length:欄]]
は必須ではありません。それが無くても長さが特定出来る場合は
省略出来るのです。ですが、上記のように CGI script
に渡される際には HTTP サーバーにより補われますので、
CGI script は安心して CONTENT_LENGTH の長さだけ標準入力を
読む、という処理が出来ます。
[28] HTTP の [CODE(HTTP)[[[Content-Length]]:]] 欄の値と実際の内容長が一致しない場合のサーバーの動作に注意が必要です。 [[HTTP/1.1]] だと多分問題になるのは与えられた内容長に達する前に接続がぶちぎられた場合ですか。そういう時適切な値に渡して CGI スクリプトに渡さないといけませんね。って普通そういう時は CGI スクリプトは実行しないかも。
[29] あるいは要求で [[chunked]] が使われてるけど [CODE(HTTP)[Content-Length:]] 欄の指定もあって、両者も矛盾している時かな。こういう時に HTTP サーバーが [CODE(CGI)[CONTENT_LENGTH]] をどうするべきかは規定がないと思いますが、実際の実体の長さをちゃんと返さないと駄目ですね。たぶんほとんどの CGI スクリプトは [CODE(CGI)[CONTENT_LENGTH]] を妄信しますから。。。
[30] ほとんど (全て?) の実装では、[[メタ変数]] [CODE(CGI)[HTTP_CONTENT_LENGTH]] は提供されません。この [CODE(CGI)[CONTENT_LENGTH]] で [WEAK[(実際にクライアントが指定した値を知りたいという奇特な場合を除いて)]] 不要ですから。
[31] 本体がないときには値 [CODE(CGI)[0]] ''ではなく'' [CODE(CGI)[NULL]] または空文字列になるのに注意が必要ですね。
[32] 注意しないといけないのは、 [[chunked]] 以外の[[転送符号化]]が使われているときです。 (>>29 が chunked の場合。 CGI には規定はないですが、 HTTP によれば [CODE(HTTP)[Content-Length]] が無視されます。) [CODE(HTTP)[Content-Length]] は転送符号化の結果の含めた長さですから、サーバーがスクリプトに転送符号化を解いた形でデータを渡す時には新しい値を設定しないといけません。 (サーバーがスクリプトに渡す前に転送符号化を解釈するべきかどうかは知らないんですが、ほとんどの CGI スクリプトの実装は転送符号化の存在がないと仮定してますよね。。。)
[33] >>32 今問題になってないのは、[[要求]]で転送符号化が使われることがまだそんなに (全然?) ないからに違いない。
;; [34] [[HTTP]] [[鯖]]は[[メッセージ本体]]を[[CGIスクリプト]]に引き渡す準備が出来る前に
[[CGIスクリプト]]を起動しても良いとされていますが、 [CODE(CGI)@en[[[CONTENT_LENGTH]]]]
を設定しなければならないという制約を考えると、起動前に[[メタ変数]]を確定させなければならない実装では、
本体の長さが確定するまで[[CGIスクリプト]]を起動できないことになります。
[[HTTP]] [CODE(HTTP)@en[[[Content-Length:]]]] [[欄]]が設定されていて[[転送符号化]]が使われていない場合であっても、
[[クライアント]]が途中で通信を切断する可能性があるので、最後まで読まないと値を確定できません。
(本当にそれでいいのでしょうか。実際の[[鯖]]の実装はそうなっていないように思います。)
* [CODE(822)@en[Content-Length:]] 欄 (電子メール)
[1] [WEAK[2002-11-15 (金) 18:10]] ''[[名無しさん]]'': [[HTTP]] ではなく[[電子メイル]]や[[電子ニュース]]でも使われるのがたまに見られます。古い [[MIME]] の draft に書いてあったのではないかと思いますが、確認していません。
** 関連
[2] [WEAK[2002-11-15 (金) 18:11]] ''[[名無しさん]]'': MIME 的には [[Content-Disposition]]:欄の "size" パラメーターが後に用意されました。
[3] [WEAK[2002-11-15 (金) 18:11]] ''2'': また電子ニュースでは伝統的に [[Lines]]:欄という似たものがあります。
* 歴史
[FIG(quotation)[
[FIGCAPTION[
[15] RFC 1945 (HTTP/1.0) 10.4; RFC 2068 14.14; RFC 2616 14.13 (HTTP/1.1) Content-Length
]FIGCAPTION]
> The Content-Length entity-header field indicates the size of
the [DEL[[INS[{1945}]] Entity-Body]] [INS[[INS[{2068,2616}]] message-body]], in decimal number of octets, sent to the recipient or,
in the case of the HEAD method, the size of the [DEL[[INS[{1945}]] Entity-Body]] [INS[[INS[{2068,2616}]] entity-body]] that
would have been sent had the request been a GET.
[CODE(HTTP)[Content-Length]] 実体頭欄は、受信者に送られる [CODE(ABNF)[message-body]],
又は [CODE(HTTP)[[[HEAD]]]] method の場合には [CODE(HTTP)[[[GET]]]]
での要求だったなら送られるであろう [CODE(ABNF)[entity-body]] の寸法をオクテット数の十進数表現で示します。
>
- Content-Length = "Content-Length" ":" 1*DIGIT
> An example is
- Content-Length: 3495
> Applications [DEL[[INS[{1945}]] should]] [INS[[INS[{2068}]] SHOULD]] use this field to indicate the size of
the [DEL[[INS[{1945}]] Entity-Body]] [INS[[INS[{2068,2616}]] message-body]]
to be transferred, regardless of the media type of the entity. [DEL[[INS[{1945}]] A valid Content-Length field value is required on all HTTP/1.0 request messages containing an entity body.]] [INS[[INS[{2068}]] It must be possible for the recipient to reliably determine the end of HTTP/1.1 requests containing an entity-body, e.g., because the request has a valid Content-Length field, uses Transfer-Encoding: chunked or a multipart body.]]
応用は、実体の媒体型に関わらず、転送する [CODE(ABNF)[message-body]]
の寸法を示すのにこの欄を用いる'''べきです'''。 [DEL[妥当な [CODE(HTTP)[Content-Length]] 欄値が、実体本体を含んでいる全ての HTTP/1.0 要求メッセージに必須です。]] [INS[受信者が [CODE(ABNF)[entity-body]] を含んだ HTTP/1.1 要求の終わりを確実に決定出来るように、例えば要求が妥当な [CODE(HTTP)[Content-Length]] 欄を持つとか、 [CODE(HTTP)[[[Transfer-Encoding]]: [[chunked]]]] を使うとか、[[複数部分実体]]であるとかでなければなりません。]]
> Any Content-Length greater than or equal to zero is a valid value.
Section [DEL[[INS[{1945}]] 7.2.2]] [INS[[INS[{2068}]] 4.4]] describes how to determine the length of a [DEL[[INS[{1945}]] response entity body]] [INS[[INS[{2068}]] message-body]]
if a Content-Length is not given.
零以上のどんな Content-Length も妥当な値です。4.4節は Content-Length
がない時に message-body の長さがどう決定されるかを説明しています。
> Note[DEL[: The [INS[{1945,2068}]]]] [INS[that the [INS[{2616}]]]] meaning of this field is significantly different from the
corresponding definition in MIME, where it is an optional field
used within the "message/external-body" content-type. In HTTP,
it [DEL[[INS[{1945}]] should]] [INS[[INS[{2068}]] SHOULD]]
be used whenever the [DEL[[INS[{1945}]] entity]] [INS[[INS[{2068}]] message]]'s length can be determined prior[INS[, unless this is prohibited by the rules in section 4.4 [INS[{2616}]]]].
]FIG]
(要約: [[MIME]] の似たのとは違うのねん。)
[FIG(quotation)[
[FIGCAPTION[
[16] RFC 2616 (HTTP/1.1) 4.4 Message Length
]FIGCAPTION]
[PRE[
The transfer-length of a message is the length of the message-body as
it appears in the message; that is, after any transfer-codings have
been applied. When a message-body is included with a message, the
transfer-length of that body is determined by one of the following
(in order of precedence):
]PRE]
メッセージの transfer-length は message 中にある message-body の長さです。
これは、 transfer-codings が適用された後のものです。 message-body
がメッセージに含まれている場合、その本文の transfer-length
は次のもののいずれか一つ (優先順) で決定されます。
[PRE[
1.Any response message which "MUST NOT" include a message-body (such
as the 1xx, 204, and 304 responses and any response to a HEAD
request) is always terminated by the first empty line after the
header fields, regardless of the entity-header fields present in
the message.
]PRE]
message-body を含んでは「'''いけない'''」応答メッセージ
(1xx, 204, 304 各応答と HEAD 要求の全ての応答) は常に頭欄の後の最初の
空行で終わります。メッセージに entity-header 欄があってもです。
[PRE[
2.If a Transfer-Encoding header field (section 14.41) is present [DEL[and has any value other than "identity",]] then the transfer-length is
defined by use of the "chunked" transfer-coding (section 3.6),
unless the message is terminated by closing the connection.
]PRE]
[CODE(HTTP)[[[Transfer-Encoding]]]] 頭欄があ[DEL[って [CODE(HTTP)[[[identity]]]] 以外の値をと]]る場合、 [CODE(ABNF)[transfer-length]] は [CODE(HTTP)[[[chunked]]]]
[CODE(ABNF)[transfer-coding]] の使用により定義されます。
但しメッセージが接続を閉じることにより終わる場合を除きます。
[INS[
注 : 削除部分は errata (>>7) による。
]INS]
[PRE[
3.If a Content-Length header field (section 14.13) is present, its
decimal value in OCTETs represents both the entity-length and the
transfer-length. The Content-Length header field MUST NOT be sent
if these two lengths are different (i.e., if a Transfer-Encoding
header field is present). If a message is received with both a
Transfer-Encoding header field and a Content-Length header field,
the latter MUST be ignored.
]PRE]
Content-Length 頭欄 ([[Content-Length:欄]]) がある場合、
OCTET での10進値が entity-length と transfer-length の両方を示します。
Content-Length 頭欄はこの2つの値が異なる (つまり Transfer-Encoding
頭欄がある) 時には送っては'''なりません'''。
Transfer-Encoding 頭欄と Content-Length 欄の両方を含むメッセージを
受け取った場合は、後者は無視しないと'''いけません'''。
> 4.If the message uses the media type "multipart/byteranges", and
the [INS[t]]ransfer-length is not otherwise specified, then this
self-[INS[d]]elimiting media type defines the transfer-length.
This media type [INS[M]]UST NOT be used unless the sender knows that
the recipient can [INS[p]]arse
it; the presence in a request of a Range header
with [INS[m]]ultiple byte-range specifiers from a 1.1 client implies that
the [INS[c]]lient can parse multipart/byteranges responses.
メッセージが媒体型 "multipart/byteranges" を使用している場合、
かつ [INS[t]]ransfer-length が他で指定されていない時、この自己[INS[区]]切媒体型が
[CODE[transfer-length]] を定義します。
この媒体型は、受信者がこれを[INS[解]]析できると送信者が知っていない限り使っては'''[INS[い]]けません'''。
HTTP/1.1 クライアントからの[INS[複]]数の byte-range 指定がある Range
頭がある要求は、[INS[ク]]ライアントが multipart/byteranges
応答を解析できることを暗示しています。
[INS[
[7] 訳注: 原文欠落箇所は ''HTTP/1.1 Specification Errata'' [DEL[<http://world.std.com/~lawrence/http_errata.html#msg-len-chars>]] [INS[<http://purl.org/NET/http-errata#msg-len-chars]]
から補った。
]INS]
[PRE[
A range header might be forwarded by a 1.0 proxy that does not
understand multipart/byteranges; in this case the server MUST
delimit the message using methods defined in items 1,3 or 5 of
this section.
]PRE]
範囲頭は multipart/byteranges を理解しない HTTP/1.0 串が中継する
かもしれません。この場合、サーバーはメッセージをこの節の
1,3,5 項のいずれかで定義された方法を使って区切ら'''なければなりません'''。
[PRE[
5.By the server closing the connection. (Closing the connection
cannot be used to indicate the end of a request body, since that
would leave no possibility for the server to send back a response.)
]PRE]
[PRE[
For compatibility with HTTP/1.0 applications, HTTP/1.1 requests
containing a message-body MUST include a valid Content-Length header
field unless the server is known to be HTTP/1.1 compliant. If a
request contains a message-body and a Content-Length is not given,
the server SHOULD respond with 400 (bad request) if it cannot
determine the length of the message, or with 411 (length required) if
it wishes to insist on receiving a valid Content-Length.
]PRE]
[PRE[
All HTTP/1.1 applications that receive entities MUST accept the
"chunked" transfer-coding (section 3.6), thus allowing this mechanism
to be used for messages when the message length cannot be determined
in advance.
]PRE]
[PRE[
Messages MUST NOT include both a Content-Length header field and a
[DEL[non-identity]] transfer-coding. If the message does include a [DEL[non-identity]] transfer-coding, the Content-Length MUST be ignored.
]PRE]
[INS[
注 : 削除部分は errata (>>7) による。
]INS]
[PRE[
When a Content-Length is given in a message where a message-body is
allowed, its field value MUST exactly match the number of OCTETs in
the message-body. HTTP/1.1 user agents MUST notify the user when an
invalid length is received and detected.
]PRE]
]FIG]
[FIG(quotation)[
[FIGCAPTION[
[17] RTSP (RFC 2326) 12.14 Content-Length
]FIGCAPTION]
> This field contains the length of the content of the method (i.e.
after the double CRLF following the last header). Unlike HTTP, it
MUST be included in all messages that carry content beyond the header
portion of the message. If it is missing, a default value of zero is
assumed. It is interpreted according to [H14.14].
[5] この欄は、[RUBY[方式] [method]] の内容
(つまり、最後の頭の後の 2つの CRLF の後) の長さから成ります。
HTTP とは違って、メッセージの頭部分を超えた内容を伝える全てのメッセージはこれを含め'''なければなりません'''。
これが欠けていた場合は既定値の零とみなします。
これは [H14.14] により解釈します。
]FIG]
** CGI
[FIG(quotation)[
[FIGCAPTION[
[26] 6.1.2. CONTENT_LENGTH ([[CGI/1.1]] draft 03)
]FIGCAPTION]
>This metavariable is set to the size of the message-body
entity attached to the request, if any, in decimal number of
octets. If no data are attached, then this metavariable is
either NULL or not defined. The syntax is the same as for the
HTTP "Content-Length" header field (section 14.14, HTTP/1.1
specification [8]).
このメタ変数には、要求に添付されたメッセージ本体実体
があれば、その大きさを、10進のオクテット数で設定します。
データが添付されていない場合は、このメタ変数は NULL か未定義とします。
この構文は HTTP 「Content-Length」(内容長)頭領域
(HTTP/1.1 仕様書第14.14節) と同じです。
CONTENT_LENGTH = "" | 1*digit
Servers MUST provide this metavariable to scripts if the
request was accompanied by a message-body entity.
サーバーは、要求にメッセージ本体実体がある場合、このメタ変数を
スクリプトに提供し'''なければなりません'''。
]FIG]
** [CODE(HTMLe)@en[object]] 要素 [CODE(HTMLa)@en[content-length]] 属性 (HTML)
[12] [[XHTML2]] の [CODE(HTMLe)@en[[[object]]]] [[要素]]には
[DFN[[CODE(HTMLa)@en[[[content-length]]]] [[属性]]]]が定義されていました。
[41] 参照されている[[オブジェクト]]の[[サイズ]]を表す[[ヒント]]とされていましたが、
どのように利用されるべきかは定義されていませんでした。
[13] 最初の[[作業原案]]では、[[属性]]の一覧には載っていましたが、肝心の定義が抜けていました。
[REFS[
- [18] [CITE@en[- XHTML Object Module]] ([TIME[2002-08-06 00:20:43 +09:00]] 版) <http://www.w3.org/TR/2002/WD-xhtml2-20020805/mod-object.html#s_objectmodule>
]REFS]
[14] 2つ目の[[作業原案]]で定義が追加されました。
[REFS[
- [19] [CITE@en[- XHTML Object Module]] ([TIME[2002-12-12 23:58:38 +09:00]] 版) <http://www.w3.org/TR/2002/WD-xhtml2-20021211/mod-object.html#adef_object_content-length>
]REFS]
[42] [[XHTML2]] 全体が支持を集められず、この[[属性]]も利用されることはありませんでした。
* 実装
[317] [[wget]] は、 [[CGIスクリプト]]に [CODE(HTTP)@en[[[Content-Length:]]]]
を正しく扱えないものがあるとして、 [CODE(HTTP)@en[[[Content-Length:]]]]
を無視する [CODE[[[--ignore-length]]]] オプションを用意しています。
* メモ
[9]
[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.2>
- [6] [WEAK[2002-12-17 (火) 20:49]] ''[[名無しさん]]'': [[iモード]]に対して送るときは Content-Length: 欄は必須となります。 <http://www.nttdocomo.co.jp/mc-user/i/tag/s3.html>
[10]
[CITE[セキュリティホール memo - 2005.07]] <http://www.st.ryukoku.ac.jp/%7Ekjm/security/memo/2005/07.html#20050707_HRS>
[11] [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.3.2>
[35] [CITE@en[RFC 4463 - A Media Resource Control Protocol (MRCP) Developed by Cisco, Nuance, and Speechworks]]
( ([TIME[2011-12-04 10:31:11 +09:00]] 版))
<http://tools.ietf.org/html/rfc4463#section-5.4.9>
[36] [CITE@en[draft-wood-dtnrg-http-dtn-delivery-07 - Using HTTP for delivery in Delay/Disruption-Tolerant Networks]]
( ([TIME[2012-02-26 11:11:35 +09:00]] 版))
<http://tools.ietf.org/html/draft-wood-dtnrg-http-dtn-delivery-07#page-6>
[37] [CITE@en[RFC 6787 - Media Resource Control Protocol Version 2 (MRCPv2)]]
( ([TIME[2012-11-13 15:18:40 +09:00]] 版))
<http://tools.ietf.org/html/rfc6787#section-6.2.11>
[315] [CITE[XMLHttpRequest/send-entity-body-get-head* tests should not fail if Content-Length is 0 · Issue #980 · w3c/web-platform-tests]]
( ([TIME[2014-07-14 05:19:37 +09:00]] 版))
<https://github.com/w3c/web-platform-tests/issues/980>
[316] [CITE[chromium chromium/src/net/http/http_network_transaction.cc]]
( ([TIME[2014-07-14 05:04:37 +09:00]] 版))
<http://mxr.mozilla.org/chromium/source/src/net/http/http_network_transaction.cc#866>
[318] [CITE@en[RFC 5547 - A Session Description Protocol (SDP) Offer/Answer Mechanism to Enable File Transfer]]
( ([TIME[2014-09-13 18:22:39 +09:00]] 版))
<https://tools.ietf.org/html/rfc5547#page-30>
[319] [CITE[RFC Errata Report]]
( ([TIME[2014-11-03 06:56:27 +09:00]] 版))
<http://www.rfc-editor.org/errata_search.php?rfc=5547>