Skip to content

Commit 2c5a846

Browse files
MaxWipfliawesomekling
authored andcommitted
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.
1 parent e4f3a5f commit 2c5a846

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Userland/Services/WebServer/Client.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ void Client::handle_directory_listing(String const& requested_path, String const
237237
builder.appendff("<td><div class=\"{}\"></div></td>", is_directory ? "folder" : "file");
238238
builder.append("<td><a href=\"");
239239
builder.append(URL::percent_encode(name));
240+
// NOTE: For directories, we append a slash so we don't always hit the redirect case,
241+
// which adds a slash anyways.
242+
if (is_directory)
243+
builder.append('/');
240244
builder.append("\">");
241245
builder.append(escape_html_entities(name));
242246
builder.append("</a></td><td>&nbsp;</td>");

0 commit comments

Comments
 (0)