mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:18:11 +00:00
LibCore+WebServer+LibWeb: Make MIME type guesser take a StringView
This reverts my previous commit in WebServer and fixes the whole issue in a much better way. Instead of having the MIME type guesser take a URL (which we don't actually have in the WebServer at that point), just take a path as a StringView. Also, make use of the case-insensitive StringView::ends_with() :^)
This commit is contained in:
parent
9c14e2ea5d
commit
5043c4a3e5
4 changed files with 15 additions and 25 deletions
|
@ -70,30 +70,29 @@ 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 guess_mime_type_based_on_filename(const StringView& path)
|
||||
{
|
||||
String lowercase_url = url.path().to_lowercase();
|
||||
if (lowercase_url.ends_with(".pbm"))
|
||||
if (path.ends_with(".pbm", CaseSensitivity::CaseInsensitive))
|
||||
return "image/x‑portable‑bitmap";
|
||||
if (url.path().ends_with(".pgm"))
|
||||
if (path.ends_with(".pgm", CaseSensitivity::CaseInsensitive))
|
||||
return "image/x‑portable‑graymap";
|
||||
if (url.path().ends_with(".png"))
|
||||
if (path.ends_with(".png", CaseSensitivity::CaseInsensitive))
|
||||
return "image/png";
|
||||
if (lowercase_url.ends_with(".ppm"))
|
||||
if (path.ends_with(".ppm", CaseSensitivity::CaseInsensitive))
|
||||
return "image/x‑portable‑pixmap";
|
||||
if (lowercase_url.ends_with(".gif"))
|
||||
if (path.ends_with(".gif", CaseSensitivity::CaseInsensitive))
|
||||
return "image/gif";
|
||||
if (lowercase_url.ends_with(".bmp"))
|
||||
if (path.ends_with(".bmp", CaseSensitivity::CaseInsensitive))
|
||||
return "image/bmp";
|
||||
if (lowercase_url.ends_with(".jpg") || lowercase_url.ends_with(".jpeg"))
|
||||
if (path.ends_with(".jpg", CaseSensitivity::CaseInsensitive) || path.ends_with(".jpeg", CaseSensitivity::CaseInsensitive))
|
||||
return "image/jpeg";
|
||||
if (lowercase_url.ends_with(".svg"))
|
||||
if (path.ends_with(".svg", CaseSensitivity::CaseInsensitive))
|
||||
return "image/svg+xml";
|
||||
if (lowercase_url.ends_with(".md"))
|
||||
if (path.ends_with(".md", CaseSensitivity::CaseInsensitive))
|
||||
return "text/markdown";
|
||||
if (lowercase_url.ends_with(".html") || lowercase_url.ends_with(".htm"))
|
||||
if (path.ends_with(".html", CaseSensitivity::CaseInsensitive) || path.ends_with(".htm", CaseSensitivity::CaseInsensitive))
|
||||
return "text/html";
|
||||
if (lowercase_url.ends_with("/"))
|
||||
if (path.ends_with("/", CaseSensitivity::CaseInsensitive))
|
||||
return "text/html";
|
||||
return "text/plain";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue