drogonframework / drogonframework/drogon

`HttpController`'s `ADD_METHOD_TO` breaks in some cases

Open
#2,130 10 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
14.3k
Forks
1.4k
Avg merge
1d 13h
Merged PRs (30d)
14

Description

**Describe the bug**
I have a few `HttpController`s and `HttpSimpleController`s mixed together, and noticed today that only one of the `HttpController`s was returning status 400, which is a status code I use for incorrect input in the URL.
I went exactly to the controller in question and added a print statement to check if it was the one getting called, and it turns out it isn't.
I then prefixed its URI with something that differs from all the other controllers and then I hit the new URI, and it returned a status 200.
I went to another controller which has about the same structure but has a constant in its URI, and put a print statement and saw it had been hitting that incorrect API endpoint.

**To Reproduce**
Couldn't reproduce it within a small project, here's how the two API endpoints in question roughly look like:
```c++
class Get : public HttpController
{
public:
void asyncHandleHttpRequest(
const HttpRequestPtr& req,
std::function&& callback,
string&& city,
string&& id
);

METHOD_LIST_BEGIN
ADD_METHOD_TO(
Get::asyncHandleHttpRequest,
"/api/clients/{client-city}/{client-id}",
HttpMethod::Get,
);
METHOD_LIST_END
};

class Get2 : public HttpController
{
public:
void asyncHandleHttpRequest(
const HttpRequestPtr& req,
std::function&& callback,
string&& id
);

METHOD_LIST_BEGIN
ADD_METHOD_TO(
Get2::asyncHandleHttpRequest,
"/api/clients/users/{user-id}",
HttpMethod::Get,
);
METHOD_LIST_END
};
```
Here the API endpoint that overshadowed the other was `Get`.

Will see if I can make a reproduceable example instead once I have time.

**Expected behavior**
Should have hit the API endpoint that looks closest to the actual URL.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.