Skip to content

Commit

Permalink
[wpinet] Serve index HTML file from WebServer if available (#7780)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner authored Feb 14, 2025
1 parent 23658a8 commit e648b9c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions wpinet/src/main/native/cpp/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<std::string> dirs;
wpi::StringMap<std::string> files;
Expand Down

0 comments on commit e648b9c

Please sign in to comment.