Ultralight icon indicating copy to clipboard operation
Ultralight copied to clipboard

Use gio's mime type functions

Open SupinePandora43 opened this issue 2 years ago • 1 comments

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.

SupinePandora43 avatar Apr 25 '22 09:04 SupinePandora43

I take my words back - it returns garbage (application/x-ext-EXTENSION) instead of valid values.

SupinePandora43 avatar Jul 27 '22 12:07 SupinePandora43