From 635b460e25461b250fb098cf0bc1d61efd757c12 Mon Sep 17 00:00:00 2001 From: Paul Harris Date: Mon, 2 Sep 2024 22:10:01 +0800 Subject: [PATCH] Automatically redirect http://host/folder to http://host/folder/ This will then automatically look for the /index.html file. --- httplib.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/httplib.h b/httplib.h index f038a1f..6a6a16c 100644 --- a/httplib.h +++ b/httplib.h @@ -6474,6 +6474,11 @@ inline bool Server::handle_file_request(const Request &req, Response &res, auto path = entry.base_dir + sub_path; if (path.back() == '/') { path += "index.html"; } + if (detail::is_dir(path)) { + res.set_redirect(sub_path + "/"); + return true; + } + if (detail::is_file(path)) { for (const auto &kv : entry.headers) { res.set_header(kv.first, kv.second);