Skip to content

Commit 07125b5

Browse files
etrclaude
andcommitted
Remove deprecated register_resource alias (clean break)
register_resource was a [[deprecated]] forwarder to register_path, retained for migration. RELEASE_NOTES already presents it as gone (replaced by register_path for exact match / register_prefix for prefix), so the interim alias was the inconsistency. Remove it outright: - drop both overloads (templated unique_ptr + shared_ptr) from webserver_routes.hpp and the shared_ptr impl from webserver_register.cpp - webserver_register_path_prefix_test: replace the bool-family negative SFINAE with a clean-break pin that register_resource is gone entirely (no smart-pointer or bool-family overload survives); drop the deprecated-forwarder runtime test - webserver_register_smartptr_test: retarget the ownership tests (unique_ptr transfer, shared_ptr retention, null/duplicate throw) at register_path, drop the now-obsolete register_resource SFINAE - README: drop the "note on register_resource"; check-readme now forbids the register_resource identifier outright Callers use register_path (exact) or register_prefix (prefix). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NpysYDDJac63yz2mZKKiDf
1 parent ad7c0e8 commit 07125b5

8 files changed

Lines changed: 58 additions & 167 deletions

File tree

README.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -882,15 +882,6 @@ on the builder if you need pure literal-path semantics.
882882
remove a previously registered resource by path. (`unregister_resource`
883883
exists as a deprecated alias for `unregister_path`.)
884884

885-
### A note on `register_resource`
886-
887-
`register_resource(path, resource)` is a deprecated alias for
888-
`register_path` retained for migration convenience and marked
889-
`[[deprecated]]`. New code should call `register_path` for exact
890-
matches and `register_prefix` for subtrees.
891-
892-
[Back to TOC](#table-of-contents)
893-
894885
## Request
895886

896887
`http_request` is read-only inside a handler. The accessors are designed

scripts/check-readme.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ V1_TOKENS_ARR=(
105105
'\bbasic_auth_fail_response\b'
106106
'\bdigest_auth_fail_response\b'
107107
'new[[:space:]]+[A-Za-z_]*_response[[:space:]]*\('
108-
'register_resource[[:space:]]*\([^,]*,[[:space:]]*new[[:space:]]+'
108+
'\bregister_resource\b'
109109
'\bnot_found_resource\b'
110110
'\bmethod_not_allowed_resource\b'
111111
'\binternal_error_resource\b'

src/detail/webserver_register.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,6 @@ void webserver::register_prefix(const std::string& path,
253253
register_impl_(path, std::move(res), /*family=*/true);
254254
}
255255

256-
// Deprecated forwarder kept for backward compatibility. Users that want
257-
// prefix matching must call register_prefix().
258-
void webserver::register_resource(const std::string& resource,
259-
std::shared_ptr<http_resource> res) {
260-
register_path(resource, std::move(res));
261-
}
262-
263256
// TASK-024: erase a single registration of the requested kind (family).
264257
// Each kind keeps a distinct v2-table entry (parameterized routes live in
265258
// the radix tier, regex routes in the regex_routes_ vector, exact routes

src/httpserver/webserver.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ namespace httpserver {
8888
* threads. The thread-safety contract:
8989
*
9090
* 1. Public registration / un-registration methods (@ref register_path,
91-
* @ref register_prefix, @ref register_resource, the @ref on_get
91+
* @ref register_prefix, the @ref on_get
9292
* family, @ref route, @ref unregister_path, @ref unregister_prefix,
9393
* @ref unregister_resource, @ref register_ws_resource,
9494
* @ref unregister_ws_resource, @ref deny_ip, @ref remove_denied_ip,

src/httpserver/webserver_routes.hpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
// Carries member-function DECLARATIONS only; meant to be included from
2828
// WITHIN the body of `class webserver` defined in
2929
// httpserver/webserver.hpp. Including it elsewhere raises a #error.
30-
// Covers register_path / register_prefix / register_resource (templated
31-
// + shared_ptr overloads), the on_* HTTP-verb shortcuts (on_get,
30+
// Covers register_path / register_prefix (templated + shared_ptr
31+
// overloads), the on_* HTTP-verb shortcuts (on_get,
3232
// on_post, on_put, on_delete, on_patch, on_options, on_head), the
3333
// table-driven route() entry points, and the matching unregister_*
3434
// counterparts.
@@ -127,27 +127,6 @@ void register_prefix(const std::string& path, std::unique_ptr<T> res) {
127127
void register_prefix(const std::string& path,
128128
std::shared_ptr<http_resource> res);
129129

130-
/**
131-
* Deprecated alias for register_path(). Kept for backward compatibility;
132-
* use register_path() for exact match or register_prefix() for prefix match.
133-
*
134-
* @param path The url pointing to the resource.
135-
* @param res unique_ptr to the http_resource (or any derived type).
136-
**/
137-
template <typename T,
138-
typename = std::enable_if_t<
139-
std::is_base_of_v<http_resource, T>>>
140-
[[deprecated("use register_path() for exact match or register_prefix() for prefix match")]]
141-
// This file is included inside the webserver class body; transitive
142-
// <utility>/<memory>/<string> live in the parent webserver.hpp.
143-
void register_resource(const std::string& path, std::unique_ptr<T> res) { // NOLINT(build/include_what_you_use)
144-
register_path(path, std::move(res)); // NOLINT(build/include_what_you_use)
145-
}
146-
/// @copydoc register_resource(const std::string&, std::unique_ptr<T>)
147-
[[deprecated("use register_path() for exact match or register_prefix() for prefix match")]]
148-
void register_resource(const std::string& path,
149-
std::shared_ptr<http_resource> res); // NOLINT(build/include_what_you_use)
150-
151130
/**
152131
* Register a lambda handler for HTTP GET on @p path.
153132
*

test/Makefile.am

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -253,25 +253,23 @@ http_request_const_getters_LDADD =
253253
http_request_tls_accessors_SOURCES = unit/http_request_tls_accessors_test.cpp
254254
http_request_tls_accessors_LDADD =
255255

256-
# webserver_register_smartptr: TASK-023. Compile-time signature
257-
# assertions that the new unique_ptr/shared_ptr register_resource
258-
# overloads exist and the raw-pointer overload is gone, plus runtime
259-
# tests for ownership semantics (unique_ptr ownership transfer,
260-
# shared_ptr caller-retains-ref, throw-on-null, throw-on-duplicate).
261-
# Default LDADD (libhttpserver + curl) is sufficient; no microhttpd
262-
# direct link needed.
256+
# webserver_register_smartptr: TASK-023. Runtime tests for the
257+
# register_path smart-pointer ownership semantics (unique_ptr ownership
258+
# transfer, shared_ptr caller-retains-ref, throw-on-null,
259+
# throw-on-duplicate). The compile-time signature contract lives in
260+
# webserver_register_path_prefix. Default LDADD (libhttpserver + curl) is
261+
# sufficient; no microhttpd direct link needed.
263262
webserver_register_smartptr_SOURCES = unit/webserver_register_smartptr_test.cpp
264263

265264
# webserver_register_path_prefix: TASK-024. Compile-time signature
266265
# assertions that register_path / register_prefix exist with both
267266
# unique_ptr and shared_ptr overloads, that unregister_path /
268-
# unregister_prefix exist, and that the bool-family register_resource
269-
# overload has been removed (negative SFINAE pin for acceptance criterion
270-
# #1). Runtime tests: register_prefix matches a longer URL; register_path
271-
# does not; parameterized exact paths bind their args; unregister_path /
272-
# unregister_prefix / the umbrella unregister_resource alias all 404 the
273-
# route after removal; the [[deprecated]] register_resource forwarder
274-
# still serves and behaves like register_path.
267+
# unregister_prefix exist, and that register_resource has been removed
268+
# entirely (negative SFINAE pin — clean break; no smart-pointer or
269+
# bool-family overloads survive). Runtime tests: register_prefix matches a
270+
# longer URL; register_path does not; parameterized exact paths bind their
271+
# args; unregister_path / unregister_prefix / the umbrella
272+
# unregister_resource alias all 404 the route after removal.
275273
webserver_register_path_prefix_SOURCES = unit/webserver_register_path_prefix_test.cpp
276274

277275
# webserver_on_methods: TASK-025. Compile-time signature contract for

test/unit/webserver_register_path_prefix_test.cpp

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
// - register_path(path, ptr) -> exact match (does NOT match a longer URL)
2727
// - register_prefix(path, ptr) -> prefix match (matches the path and all
2828
// children of it)
29-
// - register_resource(path, ptr) is kept as a [[deprecated]] alias for
30-
// register_path so TASK-023-era call sites still compile.
31-
// - The 3-arg `bool family` overloads of register_resource are gone.
29+
// - register_resource is gone entirely (clean break): neither the
30+
// smart-pointer overloads nor the 3-arg `bool family` overloads exist.
31+
// Call register_path for exact match or register_prefix for prefix.
3232
//
3333
// This TU pins both the compile-time signature contract (the new methods
3434
// exist with the right shape; the bool-family overload is removed) and
@@ -150,36 +150,35 @@ static_assert(std::is_same_v<
150150
void>,
151151
"unregister_prefix(const string&) must exist and return void");
152152

153-
// (6) Negative SFINAE: the 3-arg bool-family overload of register_resource
154-
// must be gone. (Acceptance criterion #1 of TASK-024 pinned at compile
155-
// time.) The probe expression is a call with a trailing `bool` arg; if
156-
// such an overload existed, the call would be well-formed and ::value
157-
// would flip to true.
153+
// (6) Negative SFINAE: register_resource is removed entirely (clean break).
154+
// None of its historical shapes may exist — the templated unique_ptr
155+
// overload, the shared_ptr overload, or the 3-arg bool-family overloads.
156+
// The probe covers the smart-pointer shapes (the templated/typed
157+
// overloads); if any survived, the call would be well-formed and
158+
// ::value would flip to true. Callers use register_path / register_prefix.
158159
template <typename, typename = void>
159-
struct has_bool_family_register : std::false_type {};
160+
struct has_register_resource_shared : std::false_type {};
160161

161162
template <typename WS>
162-
struct has_bool_family_register<WS, std::void_t<
163+
struct has_register_resource_shared<WS, std::void_t<
163164
decltype(std::declval<WS&>().register_resource(
164165
std::declval<const std::string&>(),
165-
std::declval<std::shared_ptr<http_resource>>(),
166-
std::declval<bool>()))>> : std::true_type {};
166+
std::declval<std::shared_ptr<http_resource>>()))>> : std::true_type {};
167167

168-
static_assert(!has_bool_family_register<webserver>::value,
169-
"the bool-family register_resource overload must be removed");
168+
static_assert(!has_register_resource_shared<webserver>::value,
169+
"register_resource(const string&, shared_ptr) must be removed");
170170

171171
template <typename, typename = void>
172-
struct has_bool_family_register_unique : std::false_type {};
172+
struct has_register_resource_unique : std::false_type {};
173173

174174
template <typename WS>
175-
struct has_bool_family_register_unique<WS, std::void_t<
175+
struct has_register_resource_unique<WS, std::void_t<
176176
decltype(std::declval<WS&>().register_resource(
177177
std::declval<const std::string&>(),
178-
std::declval<std::unique_ptr<http_resource>>(),
179-
std::declval<bool>()))>> : std::true_type {};
178+
std::declval<std::unique_ptr<http_resource>>()))>> : std::true_type {};
180179

181-
static_assert(!has_bool_family_register_unique<webserver>::value,
182-
"the bool-family register_resource unique_ptr overload must be removed");
180+
static_assert(!has_register_resource_unique<webserver>::value,
181+
"register_resource(const string&, unique_ptr) must be removed");
183182

184183
// ---- Runtime behaviour tests -------------------------------------------
185184

@@ -292,26 +291,6 @@ LT_BEGIN_AUTO_TEST(webserver_register_path_prefix_suite,
292291
ws.stop();
293292
LT_END_AUTO_TEST(unregister_resource_alias_handles_both_kinds)
294293

295-
// The deprecated register_resource(path, ptr) forwarder must still compile
296-
// and behave like register_path (exact match, no longer-URL match).
297-
// Suppress the deprecation warning locally so the test binary still
298-
// builds with -Werror.
299-
LT_BEGIN_AUTO_TEST(webserver_register_path_prefix_suite,
300-
register_resource_deprecated_forwarder_behaves_like_register_path)
301-
webserver ws{create_webserver(PORT + 6)};
302-
#pragma GCC diagnostic push
303-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
304-
ws.register_resource("/d", std::make_shared<ok_resource>());
305-
#pragma GCC diagnostic pop
306-
ws.start(false);
307-
308-
LT_CHECK_EQ(fetch("localhost:8186/d").response_code, 200);
309-
// Exact-match behaviour: a longer URL must 404.
310-
LT_CHECK_EQ(fetch("localhost:8186/d/extra").response_code, 404);
311-
312-
ws.stop();
313-
LT_END_AUTO_TEST(register_resource_deprecated_forwarder_behaves_like_register_path)
314-
315294
// TASK-056: registering the SAME path as both exact and prefix is no
316295
// longer permitted (the (method, path) cache key cannot discriminate
317296
// the two kinds at lookup time, so the second call now throws
@@ -525,9 +504,9 @@ LT_END_AUTO_TEST(register_prefix_unique_ptr_transfers_ownership_and_serves)
525504

526505
// ---- Error-path tests for register_prefix (findings 9 / 32) -------------
527506
//
528-
// register_resource (deprecated alias) is tested for null / duplicate in
507+
// register_path is tested for null / duplicate in
529508
// webserver_register_smartptr_test.cpp. The tests below pin the same
530-
// invariants on the new register_prefix API surface so this TU is
509+
// invariants on the register_prefix API surface so this TU is
531510
// self-contained.
532511

533512
LT_BEGIN_AUTO_TEST(webserver_register_path_prefix_suite,

0 commit comments

Comments
 (0)