Skip to content

Commit d23d1a5

Browse files
etrclaude
andcommitted
TASK-024: register_path / register_prefix split (GREEN)
Replaces the positional `bool family` parameter on register_resource with a named-API choice between exact and prefix matching. Public surface on `webserver`: - register_path(path, ptr) -- exact-match registration. Both unique_ptr<T> and shared_ptr<http_resource> overloads, returning void. The unique_ptr<T> form is a templated inline shim that funnels into the shared_ptr overload (TASK-023's pattern) so derived types resolve unambiguously. - register_prefix(path, ptr) -- prefix-match registration. Same overload shape. - register_resource(path, ptr) -- now [[deprecated]]; thin alias for register_path. The 3-arg `bool family` overloads are GONE. - unregister_path(path) -- erase only an exact registration. - unregister_prefix(path) -- erase only a prefix registration. - unregister_resource(path) -- kind-agnostic convenience; calls both unregister_path and unregister_prefix (idempotent). Implementation moves the validation/insertion logic into a private register_impl_(path, res, family) helper so the family flag only lives in one place. The same is done for unregister: unregister_impl_ builds the http_endpoint with the correct family flag (so the erase actually finds the original key) and only touches the registered_resources_str fast-path map for non-family entries (the str map only ever held exact registrations -- this fixes a latent erase bug where unregister_resource called .erase(string) on a map<http_endpoint,...>). The single_resource validation now reads "must be registered via register_prefix" rather than "must be marked as family"; the deprecated register_resource forwarder calls register_path, so a single_resource caller doing register_resource("/", sp) now correctly throws -- they must call register_prefix("/", sp). Acceptance criteria: - `grep -E 'register_resource\([^)]+,\s*bool\s' src/httpserver/*.hpp` returns no results: the bool-family overloads are deleted. - The new test TU pins both kinds at runtime (prefix matches a longer URL; exact does not; parameterized exact path binds {id}; unregister_* and the umbrella unregister_resource alias all 404 after removal; the deprecated register_resource forwarder still serves and behaves like register_path). - All 34 testsuite entries pass under `make check -j1`. Call sites updated in this commit: - examples/*: register_resource(p, ptr, true) -> register_prefix(p, ptr). Other examples (which used register_resource for exact match) are renamed to register_path to avoid -Werror on the new [[deprecated]] forwarder. - test/integ/*: same treatment. The smartptr unit test still exercises the deprecated forwarder (that is its purpose), so it silences -Wdeprecated-declarations file-wide. - examples/url_registration.cpp gains a "/family" prefix showcase and uses register_path / register_prefix throughout to model the new API surface for users. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7d7146b commit d23d1a5

47 files changed

Lines changed: 453 additions & 360 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/allowing_disallowing_methods.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ int main() {
3535
auto hwr = std::make_shared<hello_world_resource>();
3636
hwr->disallow_all();
3737
hwr->set_allowing(httpserver::http_method::get, true);
38-
ws.register_resource("/hello", hwr);
38+
ws.register_path("/hello", hwr);
3939
ws.start(true);
4040

4141
return 0;

examples/args_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ int main() {
9090
httpserver::webserver ws = httpserver::create_webserver(8080);
9191

9292
auto ar = std::make_shared<args_resource>();
93-
ws.register_resource("/args", ar);
93+
ws.register_path("/args", ar);
9494

9595
std::cout << "Server running on http://localhost:8080/args\n";
9696
std::cout << "Try: http://localhost:8080/args?name=john&age=30\n";

examples/basic_authentication.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int main() {
3939
httpserver::webserver ws = httpserver::create_webserver(8080);
4040

4141
auto hwr = std::make_shared<user_pass_resource>();
42-
ws.register_resource("/hello", hwr);
42+
ws.register_path("/hello", hwr);
4343
ws.start(true);
4444

4545
return 0;

examples/benchmark_nodelay.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int main(int argc, char** argv) {
5252
hello->with_header("Server", "libhttpserver");
5353

5454
auto hwr = std::make_shared<hello_world_resource>(hello);
55-
ws.register_resource(PATH, hwr, false);
55+
ws.register_path(PATH, hwr);
5656

5757
ws.start(true);
5858

examples/benchmark_select.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int main(int argc, char** argv) {
5151
hello->with_header("Server", "libhttpserver");
5252

5353
auto hwr = std::make_shared<hello_world_resource>(hello);
54-
ws.register_resource(PATH, hwr, false);
54+
ws.register_path(PATH, hwr);
5555

5656
ws.start(true);
5757

examples/benchmark_threads.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int main(int argc, char** argv) {
5050
hello->with_header("Server", "libhttpserver");
5151

5252
auto hwr = std::make_shared<hello_world_resource>(hello);
53-
ws.register_resource(PATH, hwr, false);
53+
ws.register_path(PATH, hwr);
5454

5555
ws.start(true);
5656

examples/binary_buffer_response.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ int main() {
7474
httpserver::webserver ws = httpserver::create_webserver(8080);
7575

7676
auto ir = std::make_shared<image_resource>();
77-
ws.register_resource("/image", ir);
77+
ws.register_path("/image", ir);
7878
ws.start(true);
7979

8080
return 0;

examples/centralized_authentication.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ int main() {
6363
auto hello = std::make_shared<hello_resource>();
6464
auto health = std::make_shared<health_resource>();
6565

66-
ws.register_resource("/api", hello);
67-
ws.register_resource("/health", health);
66+
ws.register_path("/api", hello);
67+
ws.register_path("/health", health);
6868

6969
ws.start(true);
7070

examples/client_cert_auth.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ int main() {
157157
auto secure = std::make_shared<secure_resource>();
158158
auto info = std::make_shared<info_resource>();
159159

160-
ws.register_resource("/secure", secure);
161-
ws.register_resource("/info", info);
160+
ws.register_path("/secure", secure);
161+
ws.register_path("/info", info);
162162

163163
std::cout << "Server started. Press Ctrl+C to stop.\n\n";
164164
std::cout << "Test commands:\n";

examples/custom_access_log.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int main() {
4040
.log_access(custom_access_log);
4141

4242
auto hwr = std::make_shared<hello_world_resource>();
43-
ws.register_resource("/hello", hwr);
43+
ws.register_path("/hello", hwr);
4444
ws.start(true);
4545

4646
return 0;

0 commit comments

Comments
 (0)