Content-Type metadata

Content-Type: ヘッダー (MIME、HTTP)

[14] Content-Type: ヘッダーは、 対応するデータの型 (MIME型) を指定するものです。

[878] 現在用いられている Content-Type: の仕組みは、はじめ MIME電子メールのために導入され、その後 HTTP など色々なプロトコルでも採用されたものです。

仕様書

意味

[879] HTTP では、関連付けられた表現MIME型を表します。 同じメッセージpayload body が含まれていれば、その MIME型です。 HEAD メソッドに対する応答の時は、 GET メソッドだったとしたら応答に含まれるであろう表現MIME型です。 >>877

[888] 実際に表現メッセージに含まれる場合にはそのMIME型を表しますが、 HTTP HEAD メソッドに対する応答では、 GET だったなら返される表現MIME型を表します。

文脈

[219] HTTP OPTIONS 要求payload body を含める場合、 Content-Type: ヘッダー生成しなければなりません >>218

[41] WebDAV クライアントからの PUT 要求にあっては、新しい資源Content-Type: がわかっているなら、これを指定するべきです >>40

[43] FCAST でも Content-Type: HTTPヘッダーを使うことができます >>42

構文

[22] Content-Type: ヘッダーの値は、 MIME型です。引数を含めることもできます。 >>877

[881] 構文の子細は規格によって異なりますが、 おおむね次のように表せます。

[23] 例えば MIME では、 >>881 の構文字句間に LWS を挿入できます。 亜型引数名の大文字・ 小文字や引数指定の順序は意味を持ちません。 HTTP は MIME とほぼ同じですが、 引数値の定義 (>>881 では省略しています。) に使われている token の定義が少々異なります。

[34] DAV:getcontentype 特性では、 Content-Type: ヘッダーOWSBWS を含めるべきではありません >>36

[24] また、 MIME は RFC 2231 で改訂され、 実際に実体の頭部に出現する構文で >>22 よりも複雑な指定方法が使えるようになっています。 (長い引数値を電子メイルで使う場合の対策や言語指定を含める手段が用意されています。) しかし、 HTTP など MIME から派生したプロトコルにまでこの改訂が及ぶのかどうかは曖昧になっています。 (HTTP のように仕様書で構文を再定義している仕様は影響しないという説が有力です。)

MIME/HTTP/CGI/RTSP/SIP/son-of-1036/Usefor の構文の差異の詳細

省略

MIME の既定値: text/plain; charset=US-ASCII

[48] 本体部分Content-Type: が指定されない場合、 text/plain; charset=US-ASCII を表しています >>47

[49] ただし multipart/digest では message/rfc822 を表しています >>47

[882] HTTP においては、 payload body を含むメッセージ生成する送信者は、 含まれる表現MIME型が分からない場合を除き、 Content-Type: ヘッダー生成するべきです >>877

[883] HTTP においては、 Content-Type: ヘッダーがなければ、受信者MIME型application/octet-stream であるとみなしても構いませんし、 sniffing しても構いません。 >>877

[27] BEEP における MIME 実体Content-Type: 頭欄が省略された場合の既定値application/octet-stream です。 RFC 3080 2.2

解釈の変え方

既定値の章と統合する

[21] 電子メイル (822) の Content-Type: 欄の規定は RFC 1049MIME の2種類があります。両者の構文は全然違います。

同じメッセージに MIME-Version: 欄があれば MIME によって解釈し、なければ RFC 1049 で解釈するのが正しいそうです。 (という話は仕様書には載っていなくて、ietf-822 かどこかでそう聞きました。)

(もっとも、構文が全然違うのでどちらの構文も扱えるようにするのは難しくありませんし、 古いメッセージを扱わないのであれば RFC 1049 の構文は無視しても良いかもしれません。)

引数

[8] Content-Type: 欄には狭義の媒体型に加えて、 任意の個数の引数 (parameter) を指定できます。 引数は、名前と値の組からなります。値の解釈は名前に依存します。 そして引数の解釈は、(狭義の) 媒体型に依存します。 (引数は媒体型の属性であり、 Content-Type: 欄の属性ではありません。)

[11] 引数名は、大文字・小文字の区別なしで定義されています。 MIME など多くの規格では、頭欄に大文字・ 小文字どちらで書いても同じ意味です。引数名として使用できる文字は、 規格によって異なります。 MIME と HTTP では共に token ですが、その token の定義が両規格で異なります。現実に使われている文字は token で使える文字の共通集合の更に小さな部分集合です。

[18] 引数値では、大文字・小文字を区別するかどうかは 引数名 (正確には、媒体型と引数名) に依存します。 例えば、 text/plaincharset 引数では区別しませんが、 application/octet-streamname では区別します。

MIME では、引数値は value であり、 token または quoted-string として定義されていますから、 前者では引数名同様の文字種しか使えませんが、後者により RFC 822 で使えるすべての ASCII 文字が使えます。 それでも使える文字はわずかに限られますが、 RFC 2231 の方法で事実上あらゆる文字の指定が可能です。

HTTP でも tokenquoted-string が使えますが、前述のように token の定義は MIME と異なりますし、 quoted-string の定義も異なります。 RFC 2231 の方法は使用できないと一般には考えられています。

MIME・HTTP 以外の規格も tokenquoted-string が使えることが多いですが、 詳細はばらばらです。

[19] 引数は媒体型の定義と共に登録することになっています。 そのためか、電子メイルや MIME の多くの他の字句のような名前付けに関する規定がありません。 (x- で始まる引数名を私用してもよいという規定もありません。)

比較的共通なパラメーター

[16] >>8 の通り、引数は媒体型各々固有のものであるのが原則ですが、 必然的に、または間違いにより、 媒体型にかかわらず比較的共通に使われている引数が何種類か存在します。

引数名説明備考
charsetCharset
x-mac-creator作成プログラム識別子 (Macintosh)
x-mac-type型 (Macintosh)
nameファイル名Content-Dispositionfilename 引数を使用するべき
x-unix-modeアクセス権 (Un|x)

[9] charset 引数は、 MIME 本体規格でも特別に定義されている引数です。 MIME では text/* で使うことを規定していますが、 他の媒体型でも同じ、または似た意味でよく使われます。

[18] name 引数は、古い MIME の規格で application/octet-stream などごく一部の媒体型に定義されていましたが、 任意の媒体型でファイル名を指定するためのものとして間違って実装されました。 現在の MIME には Content-Disposition: 欄に filename 引数があり、最近のほとんどの UAはそちらに移行しています。

[10] x-unix-mode0777 のように Un|x におけるファイルの permission を指定するようです。 AppleMail などが使用していることがわかっています。

x-mac-creatorx-mac-type は、 Macintosh のファイル・システムの属性を記述するようです。 application/applefile (>>1) をご覧下さい。

これら3つの引数は、本来は Content-Disposition: 欄に入れたほうが良い情報かもしれません。

[33] HTTP でも name 引数が指定されることがあります。

どうやら、 Bugzilla添付ファイルname 引数ファイル名を指定しているようです。

処理

[28] Content-Disposition: ヘッダーhandling 引数は、 SIP において未対応の内容型が指定された時の処理を指定します。

handling を参照。

[45] FCAST の実装は、 Content-Type: HTTP ヘッダーに対応しなければなりません >>44

指定値の決定

[57] Content-Type: ヘッダーで指定された値は (computed MIME type に対して) supplied MIME type と呼ばれ、 check-for-apache-bug flag と共に応答から supplied MIME type detection algorithm で次のように決定されます >>58

  1. [62] check-for-apache-bug flag を、に設定します。
  2. [60] を、応答ヘッダーリスト最後Content-Type ヘッダーの値に設定します。
  3. [59] 応答HTTP応答の場合、
    1. [61] が次のいずれかであれば、 check-for-apache-bug flag を、に設定します。
      バイト列 ASCII として解釈した文字列
      74 65 78 74 2F 70 6C 61 69 6Etext/plain
      74 65 78 74 2F 70 6C 61 69 6E 3B 20 63 68 61 72 73 65 74 3D 49 53 4F 2D 38 38 35 39 2D 31text/plain; charset=ISO-8859-1
      74 65 78 74 2F 70 6C 61 69 6E 3B 20 63 68 61 72 73 65 74 3D 69 73 6F 2D 38 38 35 39 2D 31text/plain; charset=iso-8859-1
      74 65 78 74 2F 70 6C 61 69 6E 3B 20 63 68 61 72 73 65 74 3D 55 54 46 2D 38text/plain; charset=UTF-8
  4. [63] が非構文解析可能MIME型の場合、
    1. [64] check-for-apache-bug flag を返します。
  5. [65] それ以外の場合、
    1. [66] nullcheck-for-apache-bug flag を返します。

[67] ファイルの場合はファイルシステムプラットフォームの設定から決定される MIME型になり、 check-for-apache-bug flag は設定されません。 data: の場合 check-for-apache-bug flag は設定されません。 FTP の場合、仕様書には MIME型の指定があれば使う >>58 とありますが、実際には指定されることはないと思われます。ただし FTP over HTTP の場合は HTTP の場合同様に扱うべきと思われます。

[68] 複数の Content-Type: ヘッダーが指定された場合、 常に最後のものが使われます。最初のものが非構文解析可能MIME型で最後のものが非構文解析可能MIME型であっても、最後のものが採用され、 指定なしと扱われます。

[69] supplied MIME typecheck-for-apache-bug flag は、算出MIME型の決定時に参照されます。

要求メッセージの処理

[893] 要求メッセージMIME型が処理できないときは、 415 応答を返すことができます。

meta 要素から符号化を取り出す算法

[855] HTML では meta 要素から符号化を取り出す算法 (algorithm for extracting an encoding from a meta element) が定義されており、 meta 要素http-equiv 属性Content-Type の時に文字符号化 (charset) の値を取り出す時に使われます。

[857] 元々の HTTPContent-Type: 欄の構文と HTMLmeta 要素の構文には細かな違いがあり、この算法HTML の構文に特化しています。

実装

パラメーター不認識問題

[1] 主に古い時代の HTTP UA において、パラメーターの存在を知らないためにうまく扱えないことがあります。

単に無視するだけならまだ良いのですが、中にはパラメーターも含めて一つの媒体型とみなし、例えば text/html;charset=iso-2022-jp という媒体型と認識し、保存しますか? と聞いてきたりします。

[2] Mosaic variant にこういうのがいるみたいです。 古い Mosaic は対応していなかったんでしょうか? 同じ 1996年の Mosaic でも、 MosaicView (NEC) はちゃんと扱えるのに Infomosaic (富士通) は扱えなかったりします。

[3] ちなみに、古い NN (2以前) は charsetパラメーターの扱いにまた別の問題があります。

  • [12] 古い UA には、 text/html;charset=iso-2022-jp ではなく text/html; charset=iso-2022-jp になっていないと認識しない困ったちゃんがいるらしいです。
  • [13] application/x-www-form-urlencoded (>>1) にも同様の問題が存在します。おそらく潜在的に少なからぬ数の UA (おそらく大多数は特定目的の tool か古代の WWW ブラウザ。) が、パラメータの存在により誤動作又は動作しなくなる虞があります。

歴史

[15] 初め RFC 1049 が定義していましたが、これと互換性のない MIME が再定義した形式が普及し、 HTTP など他のプロトコルでも採用されています。

RFC 1049 の CT: は MIME の CT: とは互換性がありません。 また、 1049 の型の全てに対応する Internet (MIME) 媒体型が 定義されたわけでもありません。 幾ら RFC 1049 が実際にはあまり使われなかったとはいえ、 ひどい処遇です。

son-of-RFC1036 は RFC 1341 を参照していて、別途 CT: 領域を定義していません。 usefor-article もそうです。

HTTP の定義は RFC 2045 と同じ物ですが、 RFC 2231 の拡張に 追随していません。 CGI の定義は HTTP と同じです。

MIME//parameter値拡張 RFC 2184, RFC 2231 により Content-Type: 領域の parameter の定義などが 修訂されました。実際にはあまり実装されていません。

関連

[25] XML要素内容として Base16 または Base64 で含められたものの媒体型を記述するための xmlmime:contentType 属性があります。取り得る値は RFC 2045 (MIME) の Content-Type: 欄本体と同じです。 (特に注記がないから LFWS も認められるのか!?)

Describing Media Content of Binary Data in XML http://www.w3.org/TR/2005/NOTE-xml-media-types-20050504/#contentType

メモ

  • [1] 2002-11-15 (金) 17:27 名無しさん: RFC 1049 は (MIME が出たかなり後まで) Internet Standard でしたが、いつのまにか histrical に降格していました。
  • [2] MIME では Content-Type: 欄の本体の値が媒体型です。
  • [3] >>2 より媒体型のことを Content-Type あるいは内容型と呼ぶことがあります。まあ間違いではありません。好んでそう呼ぶ人も中にはいます。
  • [17] 2003-10-10 00:54:11 +00:00 名無しさん: IW:Google:"Content-Type" で41位、日本語2位。最近この WikiPage 読む人が多いのはそのせいか。

[20] Microsoft Windows XP Service Pack 2 での機能の変更点 : ブラウズのセキュリティ強化 http://www.microsoft.com/japan/technet/prodtechnol/winxppro/maintain/sp2brows.mspx

WinIE の型判別の仕様が変更されたそうです。相変わらず Content-Type 以外の情報を使うようですが、以前より幾分ましにはなっている模様。

[26] Re: Approved TAG finding: Authoritative Metadata from Ian Hickson on 2006-08-09 (www-tag@w3.org from August 2006) http://lists.w3.org/Archives/Public/www-tag/2006Aug/0027

[29] html5/cts/ (2007-09-22 11:17:46 +09:00 版) http://dev.w3.org/cvsweb/html5/cts/ (名無しさん)

[30] プロフネット (2007-11-18 14:32:36 +09:00 版) http://prof.teacup.com/fprof/?p=fprof_guide

Content-Type: text/html; charset=Shift_JIS lang=ja

(名無しさん)

[32] Bug 385166 – Gecko applies style sheets with Content-Type:"null" in standards mode (2008-01-07 19:33:34 +09:00 版) https://bugzilla.mozilla.org/show_bug.cgi?id=385166

[823] http://www.leviathansecurity.com/pdf/Flirting%20with%20MIME%20Types.pdf

Content-Encoding, Content-Transfer-Encoding との関連
拡張子、 HFS type との関係

メタ変数 CONTENT_TYPE (CGI)

[824] CGIメタ変数 CONTENT_TYPE は、 メッセージ本体 (message-body) MIME型を表します >>835HTTP などの Content-Type: に相当します。

仕様書

構文

[832] メタ変数 CONTENT_TYPE に値が設定される場合の構文は HTTPContent-Type: 頭欄の構文と同じです。

[836]

      CONTENT_TYPE = "" | media-type
      media-type   = type "/" subtype *( ";" parameter )
      type         = token
      subtype      = token
      parameter    = attribute "=" value
      attribute    = token
      value        = token | quoted-string
>>835

[837] RFC では構文は >>836 のように定義されています。これは RFC 2616HTTP の定義と一致しているのですが、 HTTPRFC とは違って LWS の挿入箇所は明記されてません。

[838] 現実には挿入される可能性があるので、仕様書の誤りだと思います。

[839] 値の意味は RFC 2616 に依るとされています >>835

既定値

[840] CONTENT_TYPE既定値はありません。CGIスクリプトは値が設定されていない場合、 その場合に限ってMIME型を受信したデータから推測して構いません。それでも不明な場合にあっては application/octet-stream として扱っても構いませんし、誤りとしても構いません。 >>835

[841] 指定されている場合であっても、 charset 引数については既定値が定義されています。

値の設定

[842] は、 HTTP 要求Content-Type: が含まれている場合、 それを設定しなければなりませんクライアントが指定しなかった場合はが推定しても構いません。 そうでない場合は設定しないべきです。 >>835

処理モデル

[851] スクリプトCONTENT_TYPE が値を持たないときは 415 応答により拒絶することができます。 >>852

歴史

CGI/1.1 Internet Draft (03)

6.1.3. CONTENT_TYPE (CGI/1.1 draft 03)

If the request includes a message-body, CONTENT_TYPE is set to the Internet Media Type [9] of the attached entity if the type was provided via a "Content-type" field in the request header, or if the server can determine it in the absence of a supplied "Content-type" field. The syntax is the same as for the HTTP "Content-Type" header field.

要求message-body を含んでいる場合、 CONTENT_TYPE は、 要求頭部Content-Type によってインターネット媒体型が指定されていればそれに設定されます。 Content-Type が明示されていない時でインターネット媒体型を決定できるときは、 それに設定されます。構文HTTPContent-Type 頭欄のものと同じです。

    CONTENT_TYPE = "" | media-type
    media-type   = type "/" subtype *( ";" parameter)
    type         = token
    subtype      = token
    parameter    = attribute "=" value
    attribute    = token
    value        = token | quoted-string

The type, subtype, and parameter attribute names are not case-sensitive. Parameter values MAY be case sensitive. Media types and their use in HTTP are described in section 3.7 of the HTTP/1.1 specification [8].

部分型引数属性名大文字・小文字を区別しません引数値大文字・小文字を区別するかもしれませんHTTP における媒体型とその用法は HTTP/1.1 仕様書の3.7節で説明されています。

Example:

application/x-www-form-urlencoded

There is no default value for this variable. If and only if it is unset, then the script MAY attempt to determine the media type from the data received. If the type remains unknown, then the script MAY choose to either assume a content-type of application/octet-stream or reject the request with a 415 ("Unsupported Media Type") error. See section 7.2.1.3 for more information about returning error status values.

この変数既定値はありません。この値が設定されていなければ、 また設定されていない場合に限り、スクリプトは受信データから 媒体型を決定しようとしても構いません]]。 それでもが未知である時は、スクリプト内容型application/octet-stream と仮定するか、 415 (「未対応の媒体型」) 誤りによって要求を却下するのどちらかを選んで構いません誤り状態値の返却についての詳細は7.2.1.3節をご覧ください。

Servers MUST provide this metavariable to scripts if a "Content-Type" field was present in the original request header. If the server receives a request with an attached entity but no "Content-Type" header field, it MAY attempt to determine the correct datatype, or it MAY omit this metavariable when communicating the request information to the script.

は、元々の要求頭部Content-Type 頭欄が存在する場合、 このメタ変数を提供しなければなりませんは、添付実体があって Content-Type 頭欄がない要求を受信した場合、 正しいデータ型を決定しようと試みて構いませんし、 スクリプト要求情報を伝える際にこのメタ変数を省いても構いません

実装

[825] CGIスクリプトCONTENT_TYPEHTTP 仕様にのっとり正しく処理していないことがよくあります。具体的には、

... というような実装があります。

[830] Perl でよく使われる CGI.pmMIME型小文字で指定されていると仮定しています。

[843] application/x-www-form-urlencoded; charset=utf-8 のように引数が指定されていると正しく扱えない CGIスクリプトも昔はよくありましたが、最近は一部のWebブラウザー引数をつけるようになったため、 正しく扱えるものが多くなっています。

関連

[831] HTTP 要求に含まれている頭欄は原則的にメタ変数 HTTP_* として CGIスクリプトに渡されますが、 Content-TypeCONTENT_TYPE は例外となっています。これは HTTP_* が存在しなかった CGI/1.0 時代の仕様に由来します。

メモ

[10] HTTP では Content-Type:欄の既定値は text/plain; charset=iso-8859-1 なんだが、 CGI ではこの既定値は採用しないってことか。

Content-Type: 欄 (CGI)

[844] CGIContent-Type: は、応答本体MIME型を表します。

仕様書

構文

[846] この欄の構文は次のように定義されています >>845

      Content-Type = "Content-Type:" media-type NL

[847] media-type の前には空白を挿入できます。 media-type>>832 で定義されています。

[848] CGI応答応答本体を含む場合、 Content-Type: 欄は必須です。それが含まれていない場合、MIME型を勝手に推定するべきではありません。 指定されている場合であっても、 charset 引数を除き、 変更せずにクライアントに送信するべきです>>845

[850] charset の項も参照。

[849] 局所リダイレクト応答では Content-Type: 欄を指定できません。

MIME Sniffing

[876] MIME型Content-Type: ヘッダーによって指定されていない場合や、 指定されていても特定の条件をみたす場合には、本体データのバイト列を検査して、 それによって MIME型を決定することがあります。これを MIME Sniffing といいます。

詳細は MIME Sniffing の項を参照してください。

Content-Type メタデータ

Content-Type メタデータが無視される場面

DAV:getcontenttype 特性 (WebDAV)

[35] DAV:getcontenttype 特性は、 accept header なしで GET した時に返されるである Content-Type: ヘッダーの値を表します >>31

[37] が自身でMIME型を割り当てるのであれば、保護特性となります >>31

[38] COPYMOVE でも特性の値を保持するべきです >>31

[39] GET に対する応答Content-Type: ヘッダーを返す WebDAV に従う資源は、この特性を定義しなければなりません >>31

関連

[880] Content-Type: によって記述されたMIME型は、 Content-Encoding: によって指定された内容符号化が適用されている場合は、 それを復号した後のデータに関するものです >>877Transfer-Encoding: によって指定された転送符号化が適用されている場合は、 それも復号した後に内容符号化復号したデータに関するものです。

歴史

RFC 1049

3. The Content-type Header Field

   Whatever structuring technique is specified by the Content-type
   field, it must be known precisely to both the sender and the
   recipient of the message in order for the message to be properly
   interpreted.  In general, this means that the allowed parameter
   values for the Content-type:  field must identify a well-defined,
   standardized, document structuring technique.  We do not preclude,
   however, the use of a Content-type:  parameter value to specify a
   private structuring technique known only to the sender and the
   recipient.
   More precisely, we propose that the Content-type:  header field
   consist of up to four parameter values.  The first, or type parameter
   names the structuring technique; the second, optional, parameter is a
   version number, ver-num, which indicates a particular version or
   revision of the standardized structuring technique.  The third
   parameter is a resource reference, resource-ref, which may indicate a
   standard database of information to be used in interpreting the
   structured document.  The last parameter is a comment.
   In the Extended Backus Naur Form of RFC-822, we have:
   Content-Type:= type [";" ver-num [";" 1#resource-ref]] [comment]

3.1. Type Values

   Initially, the type parameter would be limited to the following set
   of values:
   type:=           "POSTSCRIPT"/"SCRIBE"/"SGML"/"TEX"/"TROFF"/
                    "DVI"/"X-"atom
   These values are not case sensitive.  POSTSCRIPT, Postscript, and
   POStscriPT are all equivalent.
   POSTSCRIPT      Indicates the enclosed document consists of
                   information encoded using the Postscript Page
                   Definition Language developed by Adobe Systems,
                   Inc. [1]
   SCRIBE          Indicates the document contains embedded formatting
                   information according to the syntax used by the
                   Scribe document formatting language distributed by
                   the Unilogic Corporation. [6]
   SGML            Indicates the document contains structuring
                   information to according the rules specified for
                   the Standard Generalized Markup Language, IS 8879,
                   as published by the International Organization for
                   Standardization. [3] Documents structured according
                   to the ISO DIS 8613--Office Docment Architecture and
                   Interchange Format--may also be encoded using SGML
                   syntax.
   TEX             Indicates the document contains embedded formatting
                   information according to the syntax of the TEX
                   document production language. [4]
   TROFF           Indicates the document contains embedded formatting
                   information according to the syntax specified for the
                   TROFF formatting package developed by AT&T Bell
                   Laboratories. [5]
   DVI             Indicates the document contains information according
                   to the device independent file format produced by
                   TROFF or TEX.
   "X-"atom        Any type value beginning with the characters "X-" is
                   a private value.

3.2. Version Number

   Since standard structuring techniques in fact evolve over time, we
   leave room for specifying a version number for the content type.
   Valid values will depend upon the type parameter.
   ver-num:=      local-part
     In particular, we have the following valid values:
     For type=POSTSCRIPT
   ver-num:= "1.0"/"2.0"/"null"
     For type=SCRIBE
   ver-num:= "3"/"4"/"5"/"null"
     For type=SGML
   ver-num:="IS.8879.1986"/"null"

3.3. Resource Reference

   resource-ref:=  local-part
   As Apple has demonstrated with their implementation of the
   Laserwriter, a very general document structuring technique can be
   made more efficient by defining a set of macros or other similar
   resources to be used in interpreting any transmitted stream.  The
   Macintosh transmits a LaserPrep file to the Laserwriter containing
   font and macro definitions which can be called upon by subsequent
   documents.  The result is that documents as sent to the Laserwriter
   are considerably more compact than if they had to include the
   LaserPrep file each time.  The Resource Reference parameter allows
   specification of a well known resource, such as a LaserPrep file,
   which should be used by the receiving system when processing the
   message.
   Resource references could also include macro packages for use with
   TEX or references to preprocessors such as eqn and tbl for use with
   troff.  Allowed values will vary according to the type parameter.
     In particular, we propose the following values:
     For type = POSTSCRIPT
   resource-ref:=  "laserprep2.9"/"laserprep3.0"/"laserprep3.1"/
                   "laserprep4.0"/local-part
     For type = TROFF
   resource-ref:=  "eqn"/"tbl"/"me"/local-part

3.4. Comment

   The comment field can be any additional comment text the user
   desires.  Comments are enclosed in parentheses as specified in
   RFC-822.

拡張型

RFC 1049 に定義されていない型は IANA に登録申請できることになっていますが、 現在 IANA 登録簿でそれらしいものはありません。

非標準型

「text」型が使われていたようです(CT:省略時の既定値)。 = text/plain

IETF のメイル・サーバー mailto:mailserv@ietf.org は、 未だに Content-Type: text のメッセージを返してきます。

古い ML の archive とかには、大量の text 型のがあったりします。 (そういうメッセージは Content-Length:欄を持ってたりもします。 RFC 1049 ではないかもしれません。)

「x-uuencode-apple-single」型。中身は uuencoded Macintosh binary (未対応読者への注釈つき)っぽい。

「x-be2」。古い版の Andrew System で使われていたと、 RFC 2046 だったかに 書いてありました。 Google で探してみると、古い archive から幾つか 実例が見つかります。 Andrew Mail System の古い版とやらもどっか 探したら出て来ますかね?

この他にも、幾つかの型が使われていたっぽい形跡はありますが、 まとまった文書は見当りません。

現行(MIME) Internet 媒体型の対応

RFC1049とInternet媒体型の対応

ちなみに RFC 2049 によりますと、 MIME の CT: 定義的に不正な 値は MIME 適合 UA は application/octet-stream媒体型として 取り扱います。

RFC 2045

[866] 電子メイルで使われる Content-Type:欄の最新の定義は、 MIME RFCs の1つ目、 RFC2045 urn:ietf:rfc:2045 にあります。

RFC 2045 5. Content-Type Header Field

The purpose of the Content-Type field is to describe the data contained in the body fully enough that the receiving user agent can pick an appropriate agent or mechanism to present the data to the user, or otherwise deal with the data in an appropriate manner. The value in this field is called a media type.

Content-Type (内容型) 欄の目的は、受信した利用者エージェントが適切なエージェントやデータを利用者に提示する方法を選ぶか、その他適切な方法でデータを処理するのに十に分なだけ本体のデータを説明することにあります。この欄の値は媒体型と呼びます。

HISTORICAL NOTE: The Content-Type header field was first defined in RFC 1049. RFC 1049 used a simpler and less powerful syntax, but one that is largely compatible with the mechanism given here.

歴史について: CT 頭欄は最初 RFC 1049 で定義されました。 RFC 1049 はより簡単であまり強力ではない構文でしたが、これはここに示す仕組みとかなり互換性があります。

[868] 訳注: ほんとか? と思ったら、 RFC1049のContent-Type:領域の定義を参照。

The Content-Type header field specifies the nature of the data in the body of an entity by giving media type and subtype identifiers, and by providing auxiliary information that may be required for certain media types. After the media type and subtype names, the remainder of the header field is simply a set of parameters, specified in an attribute=value notation. The ordering of parameters is not significant.

   In general, the top-level media type is used to declare the general
   type of data, while the subtype specifies a specific format for that
   type of data.  Thus, a media type of "image/xyz" is enough to tell a
   user agent that the data is an image, even if the user agent has no
   knowledge of the specific image format "xyz".  Such information can
   be used, for example, to decide whether or not to show a user the raw
   data from an unrecognized subtype -- such an action might be
   reasonable for unrecognized subtypes of text, but not for
   unrecognized subtypes of image or audio.  For this reason, registered
   subtypes of text, image, audio, and video should not contain embedded
   information that is really of a different type.  Such compound
   formats should be represented using the "multipart" or "application"
   types.
   Parameters are modifiers of the media subtype, and as such do not
   fundamentally affect the nature of the content.  The set of
   meaningful parameters depends on the media type and subtype.  Most
   parameters are associated with a single specific subtype.  However, a
   given top-level media type may define parameters which are applicable
   to any subtype of that type.  Parameters may be required by their
   defining content type or subtype or they may be optional. MIME
   implementations must ignore any parameters whose names they do not
   recognize.
   For example, the "charset" parameter is applicable to any subtype of
   "text", while the "boundary" parameter is required for any subtype of
   the "multipart" media type.
   There are NO globally-meaningful parameters that apply to all media
   types.  Truly global mechanisms are best addressed, in the MIME
   model, by the definition of additional Content-* header fields.
   An initial set of seven top-level media types is defined in RFC 2046.
   Five of these are discrete types whose content is essentially opaque
   as far as MIME processing is concerned.  The remaining two are
   composite types whose contents require additional handling by MIME
   processors.
   This set of top-level media types is intended to be substantially
   complete.  It is expected that additions to the larger set of
   supported types can generally be accomplished by the creation of new
   subtypes of these initial types.  In the future, more top-level types
   may be defined only by a standards-track extension to this standard.
   If another top-level type is to be used for any reason, it must be
   given a name starting with "X-" to indicate its non-standard status
   and to avoid a potential conflict with a future official name.

5.1. Syntax of the Content-Type Header Field

5.1. Content-Type 頭領域の構文

In the Augmented BNF notation of RFC 822, a Content-Type header field value is defined as follows:

RFC 822 の拡張 BNF 記法により、 Content-Type 頭領域値は 次のように定義します。

     content := "Content-Type" ":" type "/" subtype
                *(";" parameter)
                ; Matching of media type and subtype
                ; is ALWAYS case-insensitive.

; 媒体型及び亜型の照合は常に大文字・小文字を区別しません。

     type := discrete-type / composite-type
     discrete-type := "text" / "image" / "audio" / "video" /
                      "application" / extension-token
     composite-type := "message" / "multipart" / extension-token
     extension-token := ietf-token / x-token
     ietf-token := <An extension token defined by a
                    standards-track RFC and registered
                    with IANA.>

; <標準化過程 RFC で定義され、 IANA に登録された拡張 token>

     x-token := <The two characters "X-" or "x-" followed, with
                 no intervening white space, by any token>

; <2文字「X-」または「x-」に、空白間隔を挟まずに続く token>

     subtype := extension-token / iana-token
     iana-token := <A publicly-defined extension token. Tokens
                    of this form must be registered with IANA
                    as specified in RFC 2048.>

; <公式に定義された拡張 token。この形式の token は RFC 2048 で規定された 通りに IANA に登録されなければならない。>

     parameter := attribute "=" value
     attribute := token
                  ; Matching of attributes
                  ; is ALWAYS case-insensitive.

; 属性の照合は常に大文字・小文字を区別しない。

     value := token / quoted-string
     token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
                 or tspecials>
     tspecials :=  "(" / ")" / "<" / ">" / "@" /
                   "," / ";" / ":" / "\" / <">
                   "/" / "[" / "]" / "?" / "="
                   ; Must be in quoted-string,
                   ; to use within parameter values

; parameter value 内で使うには常に quoted-string 内でなければならない

Note that the definition of "tspecials" is the same as the RFC 822 definition of "specials" with the addition of the three characters "/", "?", and "=", and the removal of ".".

なお、「tspecials」の定義は RFC 822 の「specials」定義から 3文字 "/", "?", "=" を加えて「.」を除いたものです。

Note also that a subtype specification is MANDATORY -- it may not be omitted from a Content-Type header field. As such, there are no default subtypes.

また、 subtype 指定は絶対必要です。 Content-Type 頭領域から 省略してはいけません。ですから、規定の亜型はありません。

The type, subtype, and parameter names are not case sensitive. For example, TEXT, Text, and TeXt are all equivalent top-level media types. Parameter values are normally case sensitive, but sometimes are interpreted in a case-insensitive fashion, depending on the intended use. (For example, multipart boundaries are case-sensitive, but the "access-type" parameter for message/External-body is not case-sensitive.)

type, subtype, parameter 名は大文字・小文字を区別しません。 例えば、 TEXT, Text, TeXt は全て同じ上位媒体型です。 parameter 値は一般に大文字・小文字を区別しますが、 その用途により区別せずに解釈されることもあります。 (例えば、 multipart 区切りは大文字・小文字を区別しますが、 message/External-body の「access-type」 parameter は 区別しません。)

Note that the value of a quoted string parameter does not include the quotes. That is, the quotation marks in a quoted-string are not a part of the value of the parameter, but are merely used to delimit that parameter value. In addition, comments are allowed in accordance with RFC 822 rules for structured header fields. Thus the following two forms

なお、引用符で囲まれた文字列の parameter の値は引用符を含みません。 これは、 quoted-string の引用符は parameter の value の一部ではなく、 単に parameter value の区切りとして使われているということです。 更に、 RFC 822 の構造化頭領域の規則に則り注釈を入れることが出来ます。 従って次の2例は完全に同等です。

     Content-type: text/plain; charset=us-ascii (Plain text)
     Content-type: text/plain; charset="us-ascii"

are completely equivalent.

Beyond this syntax, the only syntactic constraint on the definition of subtype names is the desire that their uses must not conflict. That is, it would be undesirable to have two different communities using "Content-Type: application/foobar" to mean two different things. The process of defining new media subtypes, then, is not intended to be a mechanism for imposing restrictions, but simply a mechanism for publicizing their definition and usage. There are, therefore, two acceptable mechanisms for defining new media subtypes:

    (1)   Private values (starting with "X-") may be defined
          bilaterally between two cooperating agents without
          outside registration or standardization. Such values
          cannot be registered or standardized.
    (2)   New standard values should be registered with IANA as
          described in RFC 2048.
   The second document in this set, RFC 2046, defines the initial set of
   media types for MIME.

5.2. Content-Type Defaults Content-Type 既定値

Default RFC 822 messages without a MIME Content-Type header are taken by this protocol to be plain text in the US-ASCII character set, which can be explicitly specified as:

MIME CT 頭がない既定の RFC 822 メッセージはこのプロトコルでは US-ASCII 文字集合平文とみなされ、陽に示すと次のようになります。

Content-type: text/plain; charset=us-ascii

This default is assumed if no Content-Type header field is specified. It is also recommend that this default be assumed when a syntactically invalid Content-Type header field is encountered. In the presence of a MIME-Version header field and the absence of any Content-Type header field, a receiving User Agent can also assume that plain US-ASCII text was the sender's intent. Plain US-ASCII text may still be assumed in the absence of a MIME-Version or the presence of an syntactically invalid Content-Type header field, but the sender's intent might have been otherwise.

この既定値は CT 頭欄が指定されていない時に仮定されます。構文的に不正な CT 頭欄が現れた時にもこの既定値を仮定することを推奨します。 MIME-Version 頭欄があって CT 頭欄がない時は、受信した利用者エージェントは US-ASCII の平文が送信者の意図であるとも仮定出来ます。 MIME-Version 頭欄がないか構文的に不正な CT 頭欄があるときにも US-ASCII の平文を依然仮定して構いませんが、送信者の意図は違ったかもしれません。

[867] 訳注: Draft でない現在の MIME にとって RFC 1049 の CT: 欄というのは構文的に不正なんだけど、それを US-ASCII 平文と解釈するんじゃあ、 >>868 と言ってることが矛盾していませんか。

[869] この定義は RFC 1521 の改訂版です。 (でもほとんど同じです。) RFC2231 で更に改訂されています。

usefor

[872] draft 05 6.21.2. Content-Type

The Content-Type: "text/plain" is the default type for any news article, but the recommendations and limits on line lengths set out in section 4.5 Ought to be observed

The acceptability of other subtypes of Content-Type: "text" (such as "text/html") is a matter of policy (see 1.1), and posters Ought Not to use them unless established policy or custom in the particular hierarchies or groups involved so allows. Moreover, even in those cases, for the benefit of readers who see it only in its transmitted form, the material SHOULD be "pretty-printed" (for example by restricting its line length as above and by keeping sequences which control its layout or style separate from the meaningful text).

Content-Tyoe: 「text」のほかの亜型 (「text/html」など) を認めるか は方針の問題 (1.1 参照) で、投稿者は関係する特定の階層や集団で 確立されている方針あるいは慣習の認めるところでなければ 使用するきではりません。・・・

   In the same way, Content-Types requiring special processing for their
   display, such as "application", "image", "audio", "video" and
   "multipart/related" are discouraged except in groups specifically
   intended (by policy or custom) to include them. Exceptionally, those
   application types defined in [RFC 1847] and [RFC 2015] and/or [RFC
   2015bis] for use within "multipart/signed" articles, and the type
   "application/pgp-keys" (or other similar types containing digital
   certificates) may be used freely.
   Reading agents SHOULD NOT, unless explicitly configured otherwise,
   act automatically on Application types which could change the state
   of that agent (e.g. by writing or modifying files), except in the
   case of those prescribed for use in control messages (7.2.1.2 and
   7.2.4.1).

[873] 電子メイルの MIME より厳格で、どこでも適当に comment とか WSP を 入れてはいけませぬ。

HTTP

[874] RFC 1945 (HTTP/1.0) 10.5; RFC 2068 (HTTP/1.1) 14.18; RFC 2616 (HTTP/1.1) 14.17 Content-Type

The Content-Type entity-header field indicates the media type of the {1945} Entity-Body {2068,2616} entity-body sent to the recipient or, in the case of the HEAD method, the media type that would have been sent had the request been a GET.

[5] Content-Type 実体頭欄は受信者に送られた, 又は HEAD 方式の場合では GET 要求の場合に送られる実体本体媒体型を示します。

  • [6] Content-Type = "Content-Type" ":" media-type

Media types are defined in section {1945} 3.6 {2068,2616} 3.7. An example of the field is

  • [7] Content-Type: text/html; charset=ISO-8859-4 {2068,2616}

Further discussion of methods for identifying the media type of an entity is provided in section 7.2.1.

[875] RFC 2326 (RTSP) 12.16 Content-Type

See [H14.18]. Note that the content types suitable for RTSP are likely to be restricted in practice to presentation descriptions and parameter-value types.

[4] [H14.18] 参照。 RTSP に適切な内容型は実際には表現記述と引数値の型に制限されてしまうであろうことに注意してください。

関連

[885] Document オブジェクトにおいては、 contentType 属性Content-Type: ヘッダーに相当します。

[886] 内容折衝においては、 Accept: ヘッダーが期待する表現MIME型、すなわち Content-Type: ヘッダーを指定します。

[887] HTML などのリンク系の属性にある type 属性は、リンク先の Content-Type に相当するものですが、 ヒントであって、実際の資源MIME型としては使われません。

メモ

[884] Content-Type: 欄やその値のことを、 CT と呼ぶこともあります。 但し MIME の文脈以外では普通通じませんし、 MIME な文脈でも最初に Content-Type (以下 CT) のように断っておかないと通じないかもしれません。

[833] Working Group Decision on ISSUE-125 charset-vs-quotes ( (Sam Ruby 著, 版)) http://lists.w3.org/Archives/Public/public-html/2011Mar/0304.html

[834] Apache HTTP Server Project ( ( 版)) http://httpd.apache.org/docs/1.3/misc/known_client_problems.html#content-type-persistence

[854] SOAP over Java Message Service 1.0 ( ( 版)) http://www.w3.org/TR/2012/REC-soapjms-20120216/#contentType

[862] RFC 4463 - A Media Resource Control Protocol (MRCP) Developed by Cisco, Nuance, and Speechworks ( ( 版)) http://tools.ietf.org/html/rfc4463#section-5.4.4

[863] RFC 4975 - The Message Session Relay Protocol (MSRP) ( ( 版)) http://tools.ietf.org/html/rfc4975#page-37

[864] RFC 6787 - Media Resource Control Protocol Version 2 (MRCPv2) ( ( 版)) http://tools.ietf.org/html/rfc6787#section-6.2.6

[865] RFC 2660 - The Secure HyperText Transfer Protocol ( ( 版)) http://tools.ietf.org/html/rfc2660#section-2.4.2

[870] Content-Type: text/html; みたいなのがたまにありますが、厳密には間違いですね。 (名無しさん 2004-07-11 01:22:18 +00:00)

[871] >>870 spam に多い。 (名無しさん 2004-07-11 01:25:03 +00:00)

[889] Fix request and response's body story · 578768a · whatwg/fetch ( ( 版)) https://github.com/whatwg/fetch/commit/578768a0c40b673ed9ce3e23020115af15d6ac49

[890] RFC 7252 - The Constrained Application Protocol (CoAP) ( ( 版)) http://tools.ietf.org/html/rfc7252#section-5.10.3

[894] RFC 2660 - The Secure HyperText Transfer Protocol ( ( 版)) http://tools.ietf.org/html/rfc2660#section-2.4.2

[46] Bug 28391 – Investigate missing content-type for fetching stylesheets ( 版) https://www.w3.org/Bugs/Public/show_bug.cgi?id=28391

[50] 採用とか退職とか評価に関するよもやま話 | Ryuzee.com ( 版) http://www.ryuzee.com/contents/blog/7077

Content-Type: text/html

Content-Length: 60946

Last-Modified: Fri, 18 Mar 2016 22:32:15 GMT

Connection: keep-alive

ETag: "56ec81ef-ee12"

Content-Type: text/html

Content-Type が2回
[51] orefolder.net | androidのホーム画面カスタマイズとウィジェットの情報サイト ( 版) http://www.orefolder.net/

Content-Type: text/html; charset="UTF-8"

[52] RFC 7030 - Enrollment over Secure Transport () https://tools.ietf.org/html/rfc7030#section-4.2.3

A successful response MUST be a certs-only CMC Simple PKI Response,

as defined in [RFC5272], containing only the certificate that was

issued. The HTTP content-type of "application/pkcs7-mime" with an

smime-type parameter "certs-only" is used, as specified in [RFC5273].

[53] Clarify package data algorithm for FormData (eehakkin著, ) https://github.com/whatwg/fetch/commit/e03ee6fc7f6234005a058d9784e95861b9a0a301

[54] Editorial: name mimeType variable consistently (annevk著, ) https://github.com/whatwg/fetch/commit/82c30aa94dc9efd6173d089e954d796d74f5c0f3

[55] Define MIME type extraction better (annevk著, ) https://github.com/whatwg/xhr/commit/f3377022d3f415280530f3cb03f8435955c869d6

[56] S2-045 - Apache Struts 2 Documentation - Apache Software Foundation () https://cwiki.apache.org/confluence/display/WW/S2-045

It is possible to perform a RCE attack with a malicious Content-Type value. If the Content-Type value isn't valid an exception is thrown which is then used to display an error message to a user.

[70] 個性派賃貸物件:自由に塗っちゃってください!!(room:1336) :: rooms renovation (rooms著, ) http://renovation.rooms-jp.com/room1336/

Content-Type: text/html; charset:shift_jis

[71] Define Content-Type manipulation in terms of MIME Sniffing (annevk著, ) https://github.com/whatwg/xhr/commit/edc6f8f16f58d201afb49e40ca166b8bc1ae74a3

[72] Define Content-Type manipulation in terms of MIME Sniffing by annevk · Pull Request #176 · whatwg/xhr () https://github.com/whatwg/xhr/pull/176

[73] Fix overrideMimeType() again (annevk著, ) https://github.com/whatwg/xhr/commit/121cee50b6f51215f046266642964b4c53a02a7c

[74] Editorial: rewrite send()'s body/content-type processing (domenic著, ) https://github.com/whatwg/xhr/commit/f47bbab42dabe1f52e5e9f1ed1fa6df06a6eb310

[75] Editorial: less-confusing content-type manipulation algorithm for send() · Issue #197 · whatwg/xhr () https://github.com/whatwg/xhr/issues/197

[76] Editorial: rewrite send()'s body/content-type processing by domenic · Pull Request #205 · whatwg/xhr () https://github.com/whatwg/xhr/pull/205

[77] Strengthen requirements on CORS-safelisted request-headers (annevk著, ) https://github.com/whatwg/fetch/commit/9288c8f85c809a0ac371be6843ad2cf4046ee35b

[78] Be strict on request's Content-Type (annevk著, ) https://github.com/whatwg/fetch/commit/e06e2613f9eef720d0df8640be793efca2af89bc

[79] Be strict on request's Content-Type by annevk · Pull Request #829 · whatwg/fetch () https://github.com/whatwg/fetch/pull/829

[81] Define the Content-Type header parser (annevk著, ) https://github.com/whatwg/fetch/commit/0b2bc05b2550dcbefe1321ea3e8026702514a798

[82] Define the Content-Type header parser (annevk著, ) https://github.com/whatwg/fetch/commit/0b2bc05b2550dcbefe1321ea3e8026702514a798

[83] Redesign "extract header values" and "extract header list values" · Issue #814 · whatwg/fetch () https://github.com/whatwg/fetch/issues/814

[84] "Extract a MIME type" algorithm should pick the first entry? · Issue #529 · whatwg/fetch () https://github.com/whatwg/fetch/issues/529

[85] Content-Type parsing (MIME type parsing) · Issue #30 · whatwg/mimesniff () https://github.com/whatwg/mimesniff/issues/30

[86] Define the Content-Type header parser by annevk · Pull Request #831 · whatwg/fetch () https://github.com/whatwg/fetch/pull/831

[87] チケット #47296: メールの文字コード指定 - スラド - OSDN, shibuyak, 登録: 2023-02-03 13:00, 最終更新: 2023-02-03 13:00, https://ja.osdn.net/projects/slashdotjp/ticket/47296

スラドの記事のメール受信を利用しています。時々文字化けが起こることがあり、調べてみた所、スラドから送られてくるメールの文字コード指定方法が間違っているため、メールアプリが正しくデコードできないことがあるということがわかりました。

Content-type: text/plain; charset="iso-2022-jp"

というヘッダが送られてきていますが、文字コード指定はクオートせず、

Content-type: text/plain; charset=iso-2022-jp

というのが正しいMIMEの記述です。 このため、メールアプリはこの文字コード指定を正しく解釈できず、本文を独自に文字コード判断することとなり、文面によってはたまにコードの判断を誤ることがあるようです。

[88] これは仕様書が曖昧でちょっと解釈論的には厄介なのだが、 どちらも正しいと解釈されるべきもので、これが原因で文字化けするとしたらその MUA が壊れている。