diff --git a/include/cinatra/coro_http_router.hpp b/include/cinatra/coro_http_router.hpp index 287016fa..2d4d8293 100644 --- a/include/cinatra/coro_http_router.hpp +++ b/include/cinatra/coro_http_router.hpp @@ -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 { diff --git a/include/cinatra/coro_radix_tree.hpp b/include/cinatra/coro_radix_tree.hpp index 14f76f22..1fffeea2 100644 --- a/include/cinatra/coro_radix_tree.hpp +++ b/include/cinatra/coro_radix_tree.hpp @@ -300,12 +300,12 @@ class radix_tree { if (j < m) { std::shared_ptr child( std::make_shared(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}; } diff --git a/tests/test_coro_http_server.cpp b/tests/test_coro_http_server.cpp index 2e8a8b8c..f2fd7886 100644 --- a/tests/test_coro_http_server.cpp +++ b/tests/test_coro_http_server.cpp @@ -1347,6 +1347,16 @@ TEST_CASE("test coro radix tree restful api") { }); }); + server.set_http_handler( + "/ai/robot/:messages", + [](coro_http_request &req, + coro_http_response &response) -> async_simple::coro::Lazy { + 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); @@ -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") {