Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Dec 17, 2023
1 parent bbf17fb commit b1a11a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions include/ylt/thirdparty/cinatra/coro_http_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ||
Expand Down Expand Up @@ -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<cinatra::GET>(
uri,
Expand Down
2 changes: 1 addition & 1 deletion src/coro_http/examples/chat_room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async_simple::coro::Lazy<void> 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<intptr_t, std::string> conn_map;
server.set_http_handler<cinatra::GET>(
Expand Down

0 comments on commit b1a11a0

Please sign in to comment.