h2non/filetype.py

Font mimetypes are outdated

bjd183 opened this issue · 4 comments

RFC8081 (2017) deprecated e.g. application/font-sfnt in favor of font/sfnt.

From the RFC: Deprecated Alias: The existing registration "application/font-sfnt" is deprecated in favor of "font/sfnt".

Some browsers (i.e. Chrome) issue console warnings and refuse to apply the referenced stylesheet <link rel="stylesheet" href="my.url">

Refused to apply style from 'my.url' because its MIME type ('application/font-sfnt') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Font mimetypes should be updated to reflect this change. Current workaround is to subclass font types, use add_type, and overwrite filetype.types.FONT with a new tuple to ensure correct behavior of is_font().

It is not actually possible to subclass because #165

Workaround for the workaround:

import re

for instance in filetype.font_matchers:
    match = re.match(r'^application/font-(\w+)$', instance.mime)
    suffix = match.group(1)
    instance.__class__.mime = property(lambda self: f'font/{suffix}')

Another option is to use sys.modules['filetype.types']