* [CODE(HTTP)@en[Content-Length:]] 欄 (HTTP, RTSP) ** 歴史 [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[]] [INS[>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] *** RFC の部分の License [[RFCのライセンス]] ** メモ [9] [CITE@en[RFC 3143 - Known HTTP Proxy/Caching Problems]] ([TIME[2008-08-30 12:43:01 +09:00]] 版) - [6] [WEAK[2002-12-17 (火) 20:49]] ''[[名無しさん]]'': [[iモード]]に対して送るときは Content-Length: 欄は必須となります。 [10] [CITE[セキュリティホール memo - 2005.07]] [11] [CITE@en[RFC 3143 - Known HTTP Proxy/Caching Problems]] ([TIME[2008-08-30 12:43:01 +09:00]] 版) * [CODE(822)@en[Content-Length:]] 欄 (MIME, 822) - [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]]:欄という似たものがあります。 * メタ変数 [CODE(CGI)@en[CONTENT_LENGTH]] (CGI) [8] [[CGI]] の[[メタ変数]] [DFN[[CODE(CGI)@en[[[CONTENT_LENGTH]]]]]] の値は、 [[要求]]に付随する[RUBYB[[[メッセージ本体]]]@en[message-body]]のサイズです [SRC[>>20]]。 The server MUST set this meta-variable if and only if the request is accompanied by a message-body entity. The CONTENT_LENGTH value must reflect the length of the message-body after the server has removed any transfer-codings or content-codings. ** 仕様書 [REFS[ - [20] [CITE@en[RFC 3875 - The Common Gateway Interface (CGI) Version 1.1]] ([TIME[2011-11-20 06:09:05 +09:00]] 版) ]REFS] ** 値 [4] [[要求]]に[[メッセージ本体]]が存在している場合、その場合に限り、[[鯖]]は [CODE(CGI)@en[[[CONTENT_LENGTH]]]] [[メタ変数]]を設定しなければ[['''なりません''']] [SRC[>>20]]。 [21] 値は[[メッセージ本体]]のサイズを[[オクテット]]単位の[[十進数]]で表したものです [SRC[>>20]]。 [22] [[メッセージ本体]]が付属していない場合は値は [[NULL]] ([[空文字列]] or 未設定) です [SRC[>>20]]。 [FIG[ [23] [PRE(ABNF code)[ CONTENT_LENGTH = "" | 1*digit ]PRE] [FIGCAPTION[ [SRC[>>20]] ]FIGCAPTION] ]FIG] *6.1.2. CONTENT_LENGTH ([[CGI/1.1]] draft 03) 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. サーバーは、要求にメッセージ本体実体がある場合、このメタ変数を スクリプトに提供し'''なければなりません'''。 *参考 [[HTTP]] によりますと HTTP 通信においては [[Content-Length:欄]] は必須ではありません。それが無くても長さが特定出来る場合は 省略出来るのです。ですが、上記のように CGI script に渡される際には HTTP サーバーにより補われますので、 CGI script は安心して CONTENT_LENGTH の長さだけ標準入力を 読む、という処理が出来ます。 *SEE ALSO -[[CGI]] --[[CGI/1.1]] --[[CGI/1.2]] -[[HTTP]] --[[HTTP/1.0]] --[[HTTP/1.1]] -[[RFC822と仲間達の頭領域名]] --[[Content-Length:欄]] *License [[RFCのライセンス]] - [1] HTTP の [CODE(HTTP)[[[Content-Length]]:]] 欄の値と実際の内容長が一致しない場合のサーバーの動作に注意が必要です。 [[HTTP/1.1]] だと多分問題になるのは与えられた内容長に達する前に接続がぶちぎられた場合ですか。そういう時適切な値に渡して CGI スクリプトに渡さないといけませんね。って普通そういう時は CGI スクリプトは実行しないかも。 - [2] あるいは要求で [[chunked]] が使われてるけど [CODE(HTTP)[Content-Length:]] 欄の指定もあって、両者も矛盾している時かな。こういう時に HTTP サーバーが [CODE(CGI)[CONTENT_LENGTH]] をどうするべきかは規定がないと思いますが、実際の実体の長さをちゃんと返さないと駄目ですね。たぶんほとんどの CGI スクリプトは [CODE(CGI)[CONTENT_LENGTH]] を妄信しますから。。。 - [3] ほとんど (全て?) の実装では、[[メタ変数]] [CODE(CGI)[HTTP_CONTENT_LENGTH]] は提供されません。この [CODE(CGI)[CONTENT_LENGTH]] で [WEAK[(実際にクライアントが指定した値を知りたいという奇特な場合を除いて)]] 不要ですから。 - [4] 本体がないときには値 [CODE(CGI)[0]] ''ではなく'' [CODE(CGI)[NULL]] または空文字列になるのに注意が必要ですね。 - [5] 注意しないといけないのは、 [[chunked]] 以外の[[転送符号化]]が使われているときです。 (>>2 が chunked の場合。 CGI には規定はないですが、 HTTP によれば [CODE(HTTP)[Content-Length]] が無視されます。) [CODE(HTTP)[Content-Length]] は転送符号化の結果の含めた長さですから、サーバーがスクリプトに転送符号化を解いた形でデータを渡す時には新しい値を設定しないといけません。 (サーバーがスクリプトに渡す前に転送符号化を解釈するべきかどうかは知らないんですが、ほとんどの CGI スクリプトの実装は転送符号化の存在がないと仮定してますよね。。。) - [6] >>5 今問題になってないのは、[[要求]]で転送符号化が使われることがまだそんなに (全然?) ないからに違いない。 * [CODE(HTMLe)@en[object]] 要素 [CODE(HTMLa)@en[content-length]] 属性 (XHTML2) [12] [[XHTML2]] の [CODE(HTMLe)@en[[[object]]]] [[要素]]には [DFN[[CODE(HTMLa)@en[[[content-length]]]] [[属性]]]]が定義されていました。 ** 歴史 [13] 最初の[[作業原案]]では、[[属性]]の一覧には載っていましたが、肝心の定義が抜けていました。 [REFS[ - [18] [CITE@en[- XHTML Object Module]] ([TIME[2002-08-06 00:20:43 +09:00]] 版) ]REFS] [14] 2つ目の[[作業原案]]で定義が追加されました。 [REFS[ - [19] [CITE@en[- XHTML Object Module]] ([TIME[2002-12-12 23:58:38 +09:00]] 版) ]REFS]