1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 01:37:34 +00:00

LibCore+LibWeb: Move guess-mimetype-based-on-filename logic to LibCore

This could be useful in more places.
This commit is contained in:
Andreas Kling 2020-07-27 19:49:43 +02:00
parent e3437414f0
commit 78518d230c
3 changed files with 30 additions and 27 deletions

View file

@ -70,4 +70,30 @@ void MimeData::set_text(const String& text)
set_data("text/plain", text.to_byte_buffer());
}
String guess_mime_type_based_on_filename(const URL& url)
{
String lowercase_url = url.path().to_lowercase();
if (lowercase_url.ends_with(".pbm"))
return "image/xportablebitmap";
if (url.path().ends_with(".pgm"))
return "image/xportablegraymap";
if (url.path().ends_with(".png"))
return "image/png";
if (lowercase_url.ends_with(".ppm"))
return "image/xportablepixmap";
if (lowercase_url.ends_with(".gif"))
return "image/gif";
if (lowercase_url.ends_with(".bmp"))
return "image/bmp";
if (lowercase_url.ends_with(".jpg") || lowercase_url.ends_with(".jpeg"))
return "image/jpeg";
if (lowercase_url.ends_with(".md"))
return "text/markdown";
if (lowercase_url.ends_with(".html") || lowercase_url.ends_with(".htm"))
return "text/html";
if (lowercase_url.ends_with("/"))
return "text/html";
return "text/plain";
}
}