mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:57:36 +00:00
WebServer: Force "text/html" mimetype for directories with index.html
When you GET a directory with an index.html file, we were using the mime type guessing logic from LibCore on the "/" filename, which gave us "text/plain". Force the mime type to "text/html" in these cases so browsers actually interpret it as HTML. :^)
This commit is contained in:
parent
a6aee0c097
commit
9c14e2ea5d
1 changed files with 10 additions and 1 deletions
|
@ -96,6 +96,8 @@ void Client::handle_request(ByteBuffer raw_request)
|
||||||
path_builder.append(requested_path);
|
path_builder.append(requested_path);
|
||||||
auto real_path = path_builder.to_string();
|
auto real_path = path_builder.to_string();
|
||||||
|
|
||||||
|
String forced_mime_type;
|
||||||
|
|
||||||
if (Core::File::is_directory(real_path)) {
|
if (Core::File::is_directory(real_path)) {
|
||||||
|
|
||||||
if (!request.resource().ends_with("/")) {
|
if (!request.resource().ends_with("/")) {
|
||||||
|
@ -117,6 +119,7 @@ void Client::handle_request(ByteBuffer raw_request)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
real_path = index_html_path;
|
real_path = index_html_path;
|
||||||
|
forced_mime_type = "text/html";
|
||||||
}
|
}
|
||||||
|
|
||||||
auto file = Core::File::construct(real_path);
|
auto file = Core::File::construct(real_path);
|
||||||
|
@ -125,7 +128,13 @@ void Client::handle_request(ByteBuffer raw_request)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
send_response(file->read_all(), request, Core::guess_mime_type_based_on_filename(request.url()));
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::send_response(StringView response, const HTTP::HttpRequest& request, const String& content_type)
|
void Client::send_response(StringView response, const HTTP::HttpRequest& request, const String& content_type)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue