From b1a11a0bf787de21e1fae8510932d4a70897ec58 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Sun, 17 Dec 2023 12:04:35 +0800 Subject: [PATCH] fix --- .../ylt/thirdparty/cinatra/coro_http_server.hpp | 17 +++++++++++------ src/coro_http/examples/chat_room.cpp | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/ylt/thirdparty/cinatra/coro_http_server.hpp b/include/ylt/thirdparty/cinatra/coro_http_server.hpp index bfe51e1de..6f402fde4 100644 --- a/include/ylt/thirdparty/cinatra/coro_http_server.hpp +++ b/include/ylt/thirdparty/cinatra/coro_http_server.hpp @@ -187,8 +187,8 @@ class coro_http_server { void set_transfer_chunked_size(size_t size) { chunked_size_ = size; } - void set_static_res_handler(std::string_view uri_suffix = "", - std::string file_path = "www") { + void set_static_res_dir(std::string_view uri_suffix = "", + std::string file_path = "www") { bool has_double_dot = (file_path.find("..") != std::string::npos) || (uri_suffix.find("..") != std::string::npos); if (std::filesystem::path(file_path).has_root_path() || @@ -227,10 +227,15 @@ class coro_http_server { if (size_t pos = relative_path.find('\\') != std::string::npos) { replace_all(relative_path, "\\", "/"); } - uri = fs::path("/") - .append(static_dir_router_path_) - .append(relative_path) - .string(); + if (static_dir_router_path_.empty()) { + uri = relative_path; + } + else { + uri = fs::path("/") + .append(static_dir_router_path_) + .concat(relative_path) + .string(); + } set_http_handler( uri, diff --git a/src/coro_http/examples/chat_room.cpp b/src/coro_http/examples/chat_room.cpp index c0bb25281..b98596261 100644 --- a/src/coro_http/examples/chat_room.cpp +++ b/src/coro_http/examples/chat_room.cpp @@ -51,7 +51,7 @@ async_simple::coro::Lazy broadcast(auto &conn_map, int main() { coro_http::coro_http_server server(1, 9001); - server.set_static_res_handler("", ""); + server.set_static_res_dir("", ""); std::mutex mtx; std::unordered_map conn_map; server.set_http_handler(