From e648b9c86d76a3076cc92d99455861cafb37f8a3 Mon Sep 17 00:00:00 2001 From: Jonah Bonner <47046556+jwbonner@users.noreply.github.com> Date: Thu, 13 Feb 2025 21:10:02 -0500 Subject: [PATCH] [wpinet] Serve index HTML file from WebServer if available (#7780) --- wpinet/src/main/native/cpp/WebServer.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wpinet/src/main/native/cpp/WebServer.cpp b/wpinet/src/main/native/cpp/WebServer.cpp index 9efd76a190..baa8b9b4b1 100644 --- a/wpinet/src/main/native/cpp/WebServer.cpp +++ b/wpinet/src/main/native/cpp/WebServer.cpp @@ -270,6 +270,7 @@ void MyHttpConnection::ProcessRequest() { } // generate directory listing wpi::SmallString<64> formatBuf; + fs::path indexpath = fs::path{fullpath} / "index.html"; if (qmap.Get("format", formatBuf).value_or("") == "json") { wpi::json dirs = wpi::json::array(); wpi::json files = wpi::json::array(); @@ -288,6 +289,9 @@ void MyHttpConnection::ProcessRequest() { 200, "OK", "text/json", wpi::json{{"dirs", std::move(dirs)}, {"files", std::move(files)}} .dump()); + } else if (fs::exists(indexpath)) { + SendFileResponse(200, "OK", GetMimeType("html"), indexpath, + "Content-Disposition: filename=\"index.html\"\r\n"); } else { wpi::StringMap dirs; wpi::StringMap files;