Skip to content

HttpController's ADD_METHOD_TO breaks in some cases #2130

@Mis1eader-dev

Description

@Mis1eader-dev

Describe the bug
I have a few HttpControllers and HttpSimpleControllers mixed together, and noticed today that only one of the HttpControllers 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:

class Get : public HttpController<Get>
{
public:
	void asyncHandleHttpRequest(
		const HttpRequestPtr& req,
		std::function<void (const HttpResponsePtr&)>&& 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<Get2>
{
public:
	void asyncHandleHttpRequest(
		const HttpRequestPtr& req,
		std::function<void (const HttpResponsePtr&)>&& 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions