etr / libhttpserver

C++ library for creating an embedded Rest HTTP server (and more)
GNU Lesser General Public License v2.1
882 stars 184 forks source link

[BUG] register_resource won't accept the same resource string for both family=true and family=false. #305

Closed bcsgh closed 1 year ago

bcsgh commented 1 year ago

Prerequisites

Description

The following code will fail

void RegisterResources(httpserver::webserver *ws) {
  CHECK(ws->register_resource("/", root_page, false));
  CHECK(ws->register_resource("/", fallback, true));  // This fails
}

In general, only the first register resource for any given path will be accepted, even if the resources would match differently.

The intent in this specific case is to have the second handler as a fallback that deals with anything not otherwise handled (e.g. return a 401 if not logged in or 404 otherwise). At the same time, there is still a need to handle the root URL which incidentally uses the same resource string.

I know it's possible to handle this outside the libhttpserver, but then what's the point in having register_resource at all?

Steps to Reproduce

Build a server with the above code.

Expected behavior: [What you expect to happen]

Family and non-family resources with the same path should not conflict.

Actual behavior: [What actually happens]

Regardless of family/non-family, resources with the same path conflict.

Reproduces how often: [What percentage of the time does it reproduce?]

100%

Versions