Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #530

Merged
merged 1 commit into from
Dec 17, 2023
Merged

fix #530

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading