WebServer: Append trailing slash for directory links

This adds trailing slashes to all links to directories (when listing the
directory contents). This avoids the redirect that would otherwise
happen when browsing to those directories.
This commit is contained in:
Max Wipfli 2021-06-07 13:28:51 +02:00 committed by Andreas Kling
commit 2c5a8462ec
Notes: sideshowbarker 2024-07-18 12:26:42 +09:00

View file

@ -237,6 +237,10 @@ void Client::handle_directory_listing(String const& requested_path, String const
builder.appendff("<td><div class=\"{}\"></div></td>", is_directory ? "folder" : "file");
builder.append("<td><a href=\"");
builder.append(URL::percent_encode(name));
// NOTE: For directories, we append a slash so we don't always hit the redirect case,
// which adds a slash anyways.
if (is_directory)
builder.append('/');
builder.append("\">");
builder.append(escape_html_entities(name));
builder.append("</a></td><td>&nbsp;</td>");