Skip to content

Update MimeTypes, introduce precedence#358

Open
thekid wants to merge 1 commit intoxp-framework:mainfrom
thekid:feature/update-mimetypes
Open

Update MimeTypes, introduce precedence#358
thekid wants to merge 1 commit intoxp-framework:mainfrom
thekid:feature/update-mimetypes

Conversation

@thekid
Copy link
Copy Markdown
Member

@thekid thekid commented Feb 15, 2026

This pull request updates the util.MimeTypes enumeration from https://cdn.jsdelivr.net/gh/jshttp/mime-db@latest/db.json, and adds a number of tests for well-known mime types.

Precedence used to resolve conflicts

  • application/octet-stream: 0.1
  • application/x-*: 0.7
  • */vnd.*: 0.8
  • application/*: 0.9

Script used to generate enumeration

https://gist.github.com/thekid/73ef0fbc0aea76031453cf6ec11528c5

@thekid
Copy link
Copy Markdown
Member Author

thekid commented Mar 29, 2026

A new API for mime types following their official name, "media types" (see https://www.iana.org/assignments/media-types/media-types.xhtml)

Definitions

  • A media type is represented by its template
  • A template consists of [type]/[subtype]
  • A media type may have file extensions associated with it

Usage example

$types= MediaTypes::$DEFAULT;

// Lookups by file names or extensions => 'text/plain'
$template= $types->byFileName('test.txt')->template();
$template= $types->byExtension('.txt')->template();

// Shorthand
$template= $types->templateFor('test.txt');
$template= $types->templateFor('test.txt', default: 'application/octet-stream');

// Lookup by template
$type= $types->named('text/plain');
$type->template();   // 'text/plain'
$type->type();       // 'text'
$type->subtype();    // 'plain'
$type->extensions(); // ['.txt']

// Parse type and parameters
[$type, $parameters]= $types->parse('text/plain; charset=utf-8');
$type->template($parameters); // 'text/plain; charset=utf-8'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant