You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TASK-054: migrate auth_handler_ptr to optional<http_response>
Flips the canonical auth handler typedef from
std::function<std::shared_ptr<http_response>(const http_request&)>
to
std::function<std::optional<http_response>(const http_request&)>,
completing the DR-009 / PRD-RSP-REQ-007 value-typed response rollout
onto the last remaining heap-allocating slot on the public API.
One-build escape hatch:
- compat::auth_handler_v1_ptr keeps the v1 shared_ptr-returning std::function
shape (with a [[deprecated]] attribute).
- compat::adapt_legacy_auth(legacy) wraps the v1 callable into the new
optional shape (nullptr -> nullopt; non-null -> moved-from optional).
- A [[deprecated]] create_webserver::auth_handler(compat::auth_handler_v1_ptr)
overload accepts the legacy shape and routes through adapt_legacy_auth.
Both deprecation sites cite TASK-054 and point at the new typedef.
Dispatch path: the before_handler auth-alias hook in webserver_aliases.cpp
now consumes std::optional<http_response> directly. Removes one heap
allocation per authenticated request (the shared_ptr control block);
small responses still ride the http_response SBO with zero further allocs.
Tests:
- test/unit/auth_handler_optional_signature_test.cpp NEW: static_assert
the new typedef shape; end-to-end pin nullopt-allows + engaged-rejects
via curl; hook-count invariant (+1 on before_handler).
- test/unit/auth_handler_legacy_shim_test.cpp NEW: pin the v1 typedef
alias shape, the deprecated setter overload, hook-count invariant via
the shim, and verbatim status/header forwarding through
compat::adapt_legacy_auth (proves response state is moved, not lost).
TU-scope #pragma GCC diagnostic ignored "-Wdeprecated-declarations".
- Migrated:
test/unit/hooks_alias_count_test.cpp (auth lambdas -> optional shape)
test/unit/webserver_register_path_prefix_test.cpp (reject_auth)
test/unit/create_webserver_test.cpp (builder_auth_handler)
test/integ/authentication.cpp (centralized_auth_handler)
Docs:
- README.md: setter blurb + worked example switched to optional shape.
- RELEASE_NOTES.md: added "auth handler" entry under "What changed
semantically" + rename-pair row in the v1->v2 table.
- specs/architecture/04-components/create-webserver.md: documented the
new signature, the compat alias, and the one-build deprecation window.
- src/httpserver/create_webserver.hpp: Doxygen on the setter rewritten;
TODO at lines 92-99 removed.
- examples/centralized_authentication.cpp: drops <memory>/make_shared,
returns std::optional<http_response> directly.
Verification:
- All TASK-054 new + migrated tests PASS (auth_handler_optional_signature,
auth_handler_legacy_shim, hooks_alias_count, webserver_register_path_prefix,
create_webserver, authentication).
- 73 PASS / 0 NEW FAIL in the broader test suite. 3 pre-existing baseline
segfaults (lookup_pipeline, route_table_concurrency, routing_regression)
and 6 pre-existing compile failures (basic, http_resource,
header_hygiene_iovec, iovec_entry, hook_api_shape,
hooks_per_route_resource_destroyed_first) reproduce on feature/v2.0
HEAD without these changes.
- scripts/check-examples.sh, check-readme.sh, check-release-notes.sh: OK.
- cpplint clean on new + modified files.
Note on the task action-item line: the spec says "Update the auth
short-circuit path in webserver_dispatch.cpp" -- the actual call site
post-TASK-048 is in webserver_aliases.cpp::install_default_alias_hooks_
(verified by grep -- webserver_dispatch.cpp does not reference
auth_handler). The fix is in webserver_aliases.cpp.
0 commit comments