HTTP の media type の記述中に空白文字を入れても良いのかどうか
上の記事を読んで、私も Media Types の記述中の空白文字の扱いについて気になってたことを思いだしたので調べてみました。 RFC 2045 における BNF は RFC 822 の定義のものが使用されている (?) ようですが、空白文字の扱いについてはよくわかりませんでした。
HTTP 1.1 (RFC 2616) の場合
今回の moznion さんの記事だと web ブラウザ相手っぽいので、HTTP 1.1 について調べてみることにしましょう。
RFC 2616 の拡張 BNF
RFC 2616 では、RFC 822 に似た拡張 BNF が使われています。
その定義の中に、暗黙的な linear white space について記述がありました。
RFC 2616, section 2.12.1 Augmented BNF
(中略)
- implied *LWS
- The grammar described by this specification is word-based. Except where noted otherwise, linear white space (LWS) can be included between any two adjacent words (token or quoted-string), and between adjacent words and separators, without changing the interpretation of a field. At least one delimiter (LWS and/or separators) MUST exist between any two tokens (for the definition of "token" below), since they would otherwise be interpreted as a single token.
つまり、単語ベースなので、(特に空白文字について言及がない限りは) BNF に明示的に記述されてなくても空白文字を入れてもいいよ、ってことだと思います。 多分。
RFC 2616 における Media type
で、Media type について次のように記述されていました。
RFC 2616, section 3.73.7 Media Types
HTTP uses Internet Media Types [17] in the Content-Type (section 14.17) and Accept (section 14.1) header fields in order to provide open and extensible data typing and type negotiation.
- media-type = type "/" subtype *( ";" parameter )
- type = token
- subtype = token
Parameters MAY follow the type/subtype in the form of attribute/value pairs (as defined in section 3.6).
The type, subtype, and parameter attribute names are case-insensitive. Parameter values might or might not be case-sensitive, depending on the semantics of the parameter name. Linear white space (LWS) MUST NOT be used between the type and subtype, nor between an attribute and its value. The presence or absence of a parameter might be significant to the processing of a media-type, depending on its definition within the media type registry.
強調した部分に空白文字について書かれています: 連続した空白文字 (でいいんだろうか? Linear white space?) を、type
と subtype
の間に入れてはいけないし、attribute
と value
の間に入れてもいけない。
というわけで、特に言及されてない type "/" subtype
と parameter
の間には空白文字を入れてもいいみたいですね。