Ultralight
Ultralight copied to clipboard
Use gio's mime type functions
Right now FileSystem
exposes GetFileMimeType(const String& path)
requiring a library users to implement it by themselves.
It can cause platform differences between windows (registry), macos (kUTTagClassMIMEType
) and linux (if-else).
Since ultralight bundles gio, is it possible to use it instead?
Like in: https://stackoverflow.com/a/21552150/9765252
ULString fileName = ...;
ULBuffer fileData = ...;
uint8_t* contentType = g_content_type_guess(fileName.data(), fileData.data(), fileData.size(), NULL);
ASSERT(contentType != NULL);
uint8_t* mime_type = g_content_type_get_mime_type(contentType);
g_free(contentType);
ULString mime;
mime.data = mime_type;
mime.length = getNullTerminatedLength(mime_type);
// gio's result will be freed by default ULString's `free(data)` destructor.
But it returns application/x-ext-js
instead of application/javascript
for mediaControlsLocalizedStrings.js and similarly for .dat and .pem files.
css is fine though.
I take my words back - it returns garbage (application/x-ext-EXTENSION
) instead of valid values.