Skip to content

Commit

Permalink
fix: coro router uses entire path as key
Browse files Browse the repository at this point in the history
  • Loading branch information
helintongh committed Apr 30, 2024
1 parent d2f6d0b commit fac09cf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/cinatra/coro_http_router.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class coro_http_router {

if (whole_str.find(":") != std::string::npos) {
std::string method_str(method_name);
coro_router_tree_->coro_insert(key, std::move(http_handler),
coro_router_tree_->coro_insert(whole_str, std::move(http_handler),
method_str);
}
else {
Expand Down
4 changes: 2 additions & 2 deletions include/cinatra/coro_radix_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ class radix_tree {
if (j < m) {
std::shared_ptr<radix_tree_node> child(
std::make_shared<radix_tree_node>(root->path.substr(j)));
child->handler = root->handler;
child->coro_handler = root->coro_handler;
child->indices = root->indices;
child->children = root->children;

root->path = root->path.substr(0, j);
root->handler = {};
root->coro_handler = {};
root->indices = child->path[0];
root->children = {child};
}
Expand Down
12 changes: 12 additions & 0 deletions tests/test_coro_http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,16 @@ TEST_CASE("test coro radix tree restful api") {
});
});

server.set_http_handler<cinatra::GET, cinatra::POST>(
"/ai/robot/:messages",
[](coro_http_request &req,
coro_http_response &response) -> async_simple::coro::Lazy<void> {
co_await coro_io::post([&]() {
CHECK(req.params_["messages"] == "android");
response.set_status_and_content(status_type::ok, "ok");
});
});

server.async_start();
std::this_thread::sleep_for(200ms);

Expand All @@ -1364,6 +1374,8 @@ TEST_CASE("test coro radix tree restful api") {
"hello", req_content_type::string);
client.post("http://127.0.0.1:9001/value/guilliman/cawl/yvraine", "hello",
req_content_type::string);
client.post("http://127.0.0.1:9001/ai/robot/android", "hello",
req_content_type::string);
}

TEST_CASE("test reverse proxy") {
Expand Down

0 comments on commit fac09cf

Please sign in to comment.