Function mergeMimeTypes
Merge MIME types definitions parsed from different mime/ directories.
Parameters
Name | Description |
---|---|
origin | MIME type definition that was read from a less preferable mime/ directory. |
additive | MIME type definition override from a more preferable mime/ directory. |
Throws
Exception when trying to merge MIME types with different names.
See Also
Example
import std .string : representation;
import std .exception : assertThrown;
MimeType mimeType1 = new MimeType("text/plain");
MimeType mimeType2 = new MimeType("text/xml");
assertThrown(mergeMimeTypes(mimeType1, mimeType2));
mimeType1 .name = "text/html";
mimeType2 .name = mimeType1 .name;
mimeType1 .addGlob("*.htm");
MimeMagic magic1;
magic1 .addMatch(MagicMatch(MagicMatch .Type .string_, "<HTML" .representation));
mimeType1 .addMagic(magic1);
mimeType2 .addAlias("application/html");
mimeType2 .addParent("text/xml");
mimeType2 .addXMLnamespace("http://www.w3.org/1999/xhtml", "html");
mimeType2 .deleteGlobs = true;
mimeType2 .deleteMagic = true;
mimeType2 .icon = "application-html";
mimeType2 .addGlob("*.html");
MimeMagic magic2;
magic2 .addMatch(MagicMatch(MagicMatch .Type .string_, "<html" .representation));
mimeType2 .addMagic(magic2);
auto mimeType = mergeMimeTypes(mimeType1, mimeType2);
assert(mimeType .name == mimeType1 .name);
assert(mimeType .aliases == ["application/html"]);
assert(mimeType .parents == ["text/xml"]);
assert(mimeType .XMLnamespaces == [XMLnamespace("http://www.w3.org/1999/xhtml", "html")]);
assert(mimeType .globs == [MimeGlob("*.html")]);
assert(mimeType .icon == "application-html");
assert(mimeType .magics .length == 1);
assert(mimeType .magics[0] .matches[0] .value == "<html");