diff --git a/mimesniff.bs b/mimesniff.bs index 8dce0a1..3227a94 100644 --- a/mimesniff.bs +++ b/mimesniff.bs @@ -40,6 +40,12 @@ Indent: 1 } +
+url:https://tools.ietf.org/html/rfc7230#section-3.2.6;text:token;type:dfn;spec:http +url:https://tools.ietf.org/html/rfc7230#section-3.2.6;text:quoted-string;type:dfn;spec:http +url:https://tools.ietf.org/html/rfc7231#section-3.1.1.1;text:media-type;type:dfn;spec:http ++
This specification depends on the Infra Standard. [[!INFRA]] +
An HTTP token code point is U+0021 (!), U+0023 (#), U+0024 ($), U+0025 (%), +U+0026 (&), U+0027 ('), U+002A (*), U+002B (+), U+002D (-), U+002E (.), U+005E (^), U+005F (_), +U+0060 (`), U+007C (|), U+007E (~), or an ASCII alphanumeric.
+ +This matches the value space of the token token production. [[HTTP]] + +
An HTTP quoted-string token code point is U+0009 TAB, a code point in the range +U+0020 SPACE to U+007E (~), inclusive, or a code point in the range U+0080 through +U+00FF (ÿ), inclusive. + +
This matches the effective value space of the quoted-string token +production. By definition it is a superset of the HTTP token code points. [[HTTP]] +
A binary data byte is a byte in the range 0x00 to 0x08 (NUL to BS), the byte 0x0B (VT), a byte in the @@ -139,553 +158,284 @@ Indent: 1 represented by ~. -
- The MIME type of a resource is a technical hint about the use and format - of that resource. [[!MIMETYPE]] +
- A MIME type is sometimes called an Internet media type in protocol literature, but - consistently using the term MIME type avoids confusion with the use of "media type" as - described in the Media Queries CSS specification. [[MEDIAQUERIES-4]] +
A MIME type represents an +internet media type as defined by +Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types. It can also be +referred to as a MIME type record. [[!MIMETYPE]] -
- A parsable MIME type is a MIME type for which the - parse a MIME type algorithm does not return undefined. +
Standards are encouraged to consistently use the term MIME type to avoid +confusion with the use of media type as described in Media Queries. +[[MEDIAQUERIES]] - Every parsable MIME type has a corresponding parsed MIME - type, which is the result of - parsing the parsable MIME - type. +
A MIME type's type is a non-empty ASCII string. - A parsed MIME type is made up of a type, a - subtype, and a dictionary of parameters. +
A MIME type's subtype is a non-empty +ASCII string. -
- A valid MIME type is a string that matches the
- media-type
rule defined in
- section 3.1.1.1 "Media Type" of RFC
- 7231. In particular, a valid MIME type may include parameters. [[!RFC7231]]
+
A MIME type's parameters is an ordered map +whose keys and values are ASCII strings. It is initially empty. -
- TODO: give an example of a string that is a parsable MIME type but not a - valid MIME type. -
- A valid MIME type with no parameters is a MIME type that does not contain - any U+003B SEMICOLON (;) characters. In other words, it consists only of a type and - subtype, with no parameters. +
- A serialized MIME type is the result of - serializing a parsed MIME - type. - -
- The MIME type portion of a parsable MIME type is the - result of serializing the - type and subtype of its parsed MIME - type with null parameters. +
The essence of a MIME type mimeType is +mimeType's type, followed by U+002F (/), followed by +mimeType's subtype. -
- The MIME type portion of a parsable MIME type - excludes any and all parameters. +
A MIME type is supported by the user agent if the user agent has the +capability to interpret a resource of that MIME type and present it to the user. -
- A parsable MIME type is supported by the user agent - if the user agent has the capability to interpret a resource of - that MIME type and present it to the user. +
This needs more work. See +w3c/preload #113. +
A valid MIME type string is a string that matches the +media-type token production. In particular, a valid MIME type may include +parameters. [[!RFC7231]] -
- To parse a MIME type, the user agent must execute the following - steps: +
A valid MIME type string is supposed to be used for conformance checkers only. -
"text/html
" is a valid MIME type string.
-
"text/html;
" is not a valid MIME type string, though
+ parse a MIME type returns a MIME type record for it identical to if the input had
+ been "text/html
".
+
A +valid MIME type string with no parameters is +a valid MIME type string that does not contain U+003B (;). -
").
- To parse a MIME type, given a string input, run these steps: -
Remove any leading and trailing ASCII whitespace from input. -
Let position be a position variable for input, + initially pointing at the start of input. -
Let type be the result of collecting a sequence of code points that are + not U+002F (/) from input, given position. -
/
"), continuously execute the
- following steps:
+ If type is the empty string or does not solely contain + HTTP token code points, then return failure. -
If position is past the end of input, then return failure. -
Advance position to the next code point in input. (This skips + past U+002F (/).) -
Let subtype be the result of collecting a sequence of code points that are + not U+003B (;) from input, given position. -
Remove any trailing ASCII whitespace from subtype. -
If subtype is the empty string or does not solely contain + HTTP token code points, then return failure. -
Let mimeType be a new MIME type record whose type + is type, in ASCII lowercase, and subtype is + subtype, in ASCII lowercase. -
;
"), continuously execute the following steps:
+ While position is not past the end of input: -
Advance position to the next code point in input. (This skips + past U+003B (;).) -
Skip ASCII whitespace within input given position. -
Let parameterName be the result of collecting a sequence of code points + that are not U+003B (;) or U+003D (=) from input, given position. -
Set parameterName to parameterName, in ASCII lowercase.
If position is not past the end of input, then:
If the code point at position within input is U+003B (;), + then continue. -
;
"), exit loop
- M.
-
- "
"), execute the following
- steps:
-
- "
"), execute the following steps:
-
- "
"),
- increment s by 1.
-
- \
") and
- sequence[s + 1] is not undefined, increment
- s by 1.
-
- ;
"), exit loop
- N.
-
- Advance position to the next code point in input. (This + skips past U+003D (=).) +
").
+ Let parameterValue be the empty string. -
If position is not past the end of input, then: +
If the code point at position within input is U+0022 ("), + then:
Advance position to the next code point in input.
=
"), continuously execute the following
- steps:
+ While true:
Append the result of collecting a sequence of code points that are not + U+0022 (") or U+005C (\) from input, given position, to + parameterValue.
If position is not past the end of input and the + code point at position within input is U+005C (\), then:
") and parameters[name]
- is undefined, set parameters[name] to null.
+ Advance position to the next code point in input.
If position is not past the end of input, then: -
Append the code point at position within input to + parameterValue. -
Advance position to the next code point in input. -
Continue. +
Otherwise, append U+005C (\) to parameterValue and + break. +
Otherwise, break.
=
"), exit loop
- M.
- Collect a sequence of code points that are not U+003B (;) from input, + given position. -
Given
+ text/html;charset="shift_jis"iso-2022-jp
you end up with
+ text/html;charset=shift_jis
.
").
-
- Otherwise:
Set parameterValue to the result of collecting a sequence of code + points that are not U+003B (;) from input, given position. -
Remove any trailing ASCII whitespace from parameterValue.
"
"), execute the following
- steps:
-
- "
"),
- execute the following steps:
-
- If all of the following are true -
"
"),
- increment s by 1.
+ \
") and
- sequence[s + 1] is not undefined, increment
- s by 1.
+ ;
"), execute the following steps:
-
- then set mimeType's + parameters[parameterName] to parameterValue. +
Return mimeType. +
To parse a MIME type from bytes, given a byte sequence input, +run these steps: -
- The parse a MIME type algorithm is intended to be executed after - any protocol-specific syntax within the MIME type has been - handled. +
Let string be input, isomorphic decoded. +
Return the result of parse a MIME type with string. +
- To serialize a MIME type, given a type, a - subtype, and a dictionary of parameters, execute the - following steps: - -
"), or has a length greater than
- 127, return undefined.
-
- /
"), and
- subtype.
-
- charset
" or
- "codecs
" parameters first?
-
- To serialize a MIME type, given a MIME type mimeType, run +these steps: -
;
") to serialization.
+Let serialization be the concatenation of mimeType's + type, U+002F (/), and mimeType's subtype. -
For each name → value of mimeType's + parameters: -
=
") to serialization.
+ Append U+003B (;) to serialization. -
"
") to serialization.
+ Append name to serialization. -
Append U+003D (=) to serialization. -
"
") or to the
- U+005C REVERSE SOLIDUS character
- ("\
"), append the U+005C REVERSE SOLIDUS
- character ("\
") to
- serialization.
+ If value does not solely contain HTTP token code points: -
Precede each occurence of U+0022 (") or U+005C (\) in value with U+005A (\). -
"
") to serialization.
+ Prepend U+0022 (") to value. -
Append U+0022 (") to value. +
Append value to serialization. +
;
") to serialization.
+ Return serialization. +
base64
" boolean parameter last?
+To serialize a MIME type to bytes, given a MIME type +mimeType, run these steps: -
Let stringSerialization be the result of serialize a MIME type with + mimeType. +
Return stringSerialization, isomorphic encoded. +
- An image type is any parsable MIME type where
- type is equal to "image
".
+
An audio or video type is any MIME type whose type is
+"audio
" or "video
", or whose essence is
+"application/ogg
".
-
- An audio or video type is any parsable MIME type
- where type is equal to "audio
" or
- "video
" or where the MIME type portion is
- equal to one of the following:
-
-
application/ogg
- - A font type is any parsable MIME type where - the - MIME type portion is equal to one of the following: +
A font type is any MIME type whose + +essence is one of the following:
application/vnd.ms-fontobject
- A ZIP-based type is any parsable MIME type where the
- subtype ends in "+zip
" or the MIME type
- portion is equal to one of the following:
+
A ZIP-based type is any MIME type whose subtype ends in
+"+zip
" or whose essence is one of the following:
application/zip
- An archive type is any parsable MIME type where - the - MIME type portion is equal to one of the following: +
An archive type is any MIME type whose + +essence is one of the following:
application/x-gzip
- An XML MIME type is any parsable MIME type where either the subtype
- ends in "+xml
", or the MIME type portion is equal to "text/xml
" or
- "application/xml
". [[!RFC7303]]
+
An XML MIME type is any MIME type whose subtype
+ends in "+xml
" or whose essence is "text/xml
" or
+"application/xml
". [[!RFC7303]]
-
- An HTML MIME type is any parsable MIME type where the
- MIME type portion is equal to "text/html
".
+
An HTML MIME type is any MIME type whose essence
+"text/html
".
-
- A scriptable MIME type is an XML MIME type or any - parsable MIME type where the MIME type portion is - equal to one of the following: +
A scriptable MIME type is an XML MIME type, HTML MIME type or any +MIME type whose essence is one of the following:
text/html
-
application/pdf
unknown/unknown
",
"application/unknown
", or "*/*
",
execute the rules for identifying an unknown MIME type with
@@ -2084,9 +1824,8 @@ algorithm:
Abort these steps.
text/html
", execute the
- rules for distinguishing if a resource is a feed or HTML and
+ If the supplied MIME type's essence is "text/html
",
+ execute the rules for distinguishing if a resource is a feed or HTML and
abort these steps.
User agents may implicitly extend this table to support additional parsable MIME types. +
User agents may implicitly extend this table to support additional MIME types.
However, user agents should not implicitly extend this table to include additional byte patterns for any computed MIME type already present in this table, as doing so