Goals
The MIME standard takes the following approach towards making MIMEs easier to use:
-
Define a MIME’s JavaScript API in full detail. Add a new
MIMEType
object as well for MIME manipulation.
1. Infrastructure
This specification depends on the Infra Standard. [INFRA]
Some terms used in this specification are defined in the following standards and specifications:
- Mime Sniffing [MIMESNIFF]
To set the type given a mime and type, run these steps:
-
If type is empty or does not consist entirely of HTTP token code points, throw a
TypeError
. -
Set type to type, in ASCII lowercase.
-
Set mime’s type to the value of type.
To set the subtype given a mime and subtype, run these steps:
-
If subtype is empty or does not consist entirely of HTTP token code points, throw a
TypeError
. -
Set subtype to subtype, in ASCII lowercase.
-
Set mime’s subtype to the value of subtype.
To set a parameter given a parameters, name, and value, run these steps:
-
If name is empty or does not consist entirely of HTTP token code points, throw a
TypeError
. -
If value is empty or does not consist entirely of HTTP quoted-string token code points, throw a
TypeError
. -
Set name to name, in ASCII lowercase.
-
Set parameters’ property whose name is name to the value of value.
2. API
2.1. MIMEType class
[Constructor (USVString ),
mime Exposed =(Window ,Worker )]interface {
MIMEType attribute USVString type ;attribute USVString subtype ;attribute USVString ; [
essence SameObject ]readonly attribute MIMEParams params ;stringifier USVString (); };
toJSON
A MIMEType
object has an associated mime that is a MIME and parameters that is a MIMEParams
object.
The MIMEType(mime)
constructor, when invoked, must run these steps:
-
Let mimeType be null.
-
Let mimeType be the result of running the parse a mime type on mime.
-
Let params be mimeType’s parameters.
-
Let result be a new
MIMEType
object. -
Set result’s mime to mimeType.
-
Set result’s parameters object to a new MIMEParams, and then set that parameters object’s parameters object to params.
-
Return result.
To parse a string into a MIME, invoke the MIMEType
constructor with a single argument:
var input = "text/javascript; charset=utf-8;" ,
mime = new MIMEType( input)
mime. subtype // "javascript"
This throws an exception if the input is not a valid MIME:
try {
var mime = new MIMEType( "/" )
} catch ( e) {
// that happened
}
A MIMEType
object can be used as input (while IDL requires a string as argument, a MIMEType
object stringifies to its serialized form):
var mime = new MIMEType( new MIMEType( "text/plain" ))
mime. type // "text"
The href
attribute’s getter and the toJSON()
method, when invoked, must return the serialize a mime type algorithm on context object’s mime.
The type
attribute’s getter must run these steps:
-
Return context object’s mime’s type.
The type
attribute’s setter must run these steps:
-
set the type given context object’s mime and the given value.
The subtype
attribute’s getter must run these steps:
-
Return context object’s mime’s subtype.
The subtype
attribute’s setter must run these steps:
-
set the subtype given context object’s mime and the given value.
The params
attribute’s getter must return context object’s parameters object.
2.2. MIMEParams class
[Constructor (),Exposed =(Window ,Worker )]interface {
MIMEParams void delete (USVString );
name USVString ?get (USVString );
name boolean has (USVString );
name void set (USVString ,
name USVString );
value iterable <USVString ,USVString >; };
A MIMEParams
object has an associated parameters object parameters,
which is initially null.
To create a new MIMEParams object using init, run these steps:
-
Let params be a new
MIMEParams
object. -
Return params.
The MIMEParams()
constructor, when invoked, must run these steps:
-
Return the result of running create a new MIMEParams object.
The delete(name)
method, when
invoked, must run these steps:
-
If there is not a property whose name is name in parameters, return false.
-
Delete the property whose name is name in parameters.
-
Return true.
The get(name)
method, when invoked, must return the value of the property whose name is name in parameters, if there is such a property, and null otherwise.
The has(name)
method, when invoked, must return true if there is a property whose name is name in parameters, and false otherwise.
The set(name, value)
method, when invoked, must return the result of performing set a parameter given parameters, name, and value
2.3. MIME APIs elsewhere
A standard that exposes MIMEs, should expose the MIME as a string (by
running serialize a mime type for an internal MIME’s mime). A standard should not expose a MIME using a MIMEType
object. MIMEType
objects are meant for MIME manipulation and reflection. In IDL the USVString type should be used.
The higher-level notion here is that values are to be exposed as immutable data structures.
If a standard decides to use a variant of the name "MIME" for a feature it defines, it should name such a feature "mime" (i.e., lowercase and not media type. Names such as "MIME", "MediaType", and "MIMEType" should not be used. However, if the name is a compound, "MIME" (i.e., uppercase) is preferred, e.g., "newMIME" and "oldMIME".
The EventSource
and HashChangeEvent
interfaces in HTML are examples of proper
naming. [HTML]
Acknowledgments
This standard is written by Bradley Farias (GoDaddy, bradley.meck@gmail.com).