1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:08:10 +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:
Andreas Kling 2020-10-21 21:14:16 +02:00
parent 9c14e2ea5d
commit 5043c4a3e5
4 changed files with 15 additions and 25 deletions

View file

@ -96,8 +96,6 @@ void Client::handle_request(ByteBuffer raw_request)
path_builder.append(requested_path);
auto real_path = path_builder.to_string();
String forced_mime_type;
if (Core::File::is_directory(real_path)) {
if (!request.resource().ends_with("/")) {
@ -119,7 +117,6 @@ void Client::handle_request(ByteBuffer raw_request)
return;
}
real_path = index_html_path;
forced_mime_type = "text/html";
}
auto file = Core::File::construct(real_path);
@ -128,13 +125,7 @@ void Client::handle_request(ByteBuffer raw_request)
return;
}
String mime_type;
if (!forced_mime_type.is_null())
mime_type = forced_mime_type;
else
mime_type = Core::guess_mime_type_based_on_filename(request.url());
send_response(file->read_all(), request, mime_type);
send_response(file->read_all(), request, Core::guess_mime_type_based_on_filename(real_path));
}
void Client::send_response(StringView response, const HTTP::HttpRequest& request, const String& content_type)