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: coro router uses entire path as key #573

Merged
Merged
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
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
Loading