diff options
author | Max Wipfli <mail@maxwipfli.ch> | 2021-06-07 13:28:51 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-11 11:37:15 +0200 |
commit | 2c5a8462ece5ddcc744e209298fad75d35bbe511 (patch) | |
tree | fe04e37797a5f1135b21c5e37927629015e57890 /Userland | |
parent | e4f3a5fe37f950e1ee45a93aecd30dde5963eda2 (diff) | |
download | serenity-2c5a8462ece5ddcc744e209298fad75d35bbe511.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Services/WebServer/Client.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Userland/Services/WebServer/Client.cpp b/Userland/Services/WebServer/Client.cpp index 2237a994c2..3d7d0f5be6 100644 --- a/Userland/Services/WebServer/Client.cpp +++ b/Userland/Services/WebServer/Client.cpp @@ -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> </td>"); |