Skip to content

Commit 03b80bc

Browse files
etrclaude
andcommitted
refactor: drop redundant webserver_impl::log_dispatch_error forwarder
There were two log_dispatch_error: the real free function detail::log_dispatch_error(const webserver_config&, string_view) in dispatch_util.cpp, and a one-line webserver_impl member that merely forwarded to it (parent->config, msg). The member's only two callers were the v1 auth alias hooks in webserver_aliases.cpp, which already have the owning webserver* (ws_ptr) in scope — so they can call the free function directly with ws_ptr->config. Point those two call sites at detail::log_dispatch_error, drop the member declaration (webserver_impl_dispatch.hpp) and its definition, and delete the 9-SLOC webserver_error_pages.cpp TU that existed solely to hold it. Removes a duplicate function and a translation unit; no behavior change. Local: builds, 113/113 tests pass, file-size + complexity + cpplint gates green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015tAodxYJMEY4VxCX4dk62e
1 parent e6bc48e commit 03b80bc

4 files changed

Lines changed: 9 additions & 70 deletions

File tree

src/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ lib_LTLIBRARIES = libhttpserver.la
2525
# builds. The WS-off branch in websocket_handler.cpp provides stub
2626
# definitions (every member throws feature_unavailable except is_valid()
2727
# which returns false).
28-
libhttpserver_la_SOURCES = string_utilities.cpp webserver.cpp webserver_add_hook.cpp http_utils.cpp file_info.cpp http_request.cpp http_request_auth.cpp http_response.cpp http_response_factories.cpp http_resource.cpp create_webserver.cpp create_test_request.cpp websocket_handler.cpp hook_handle.cpp peer_address.cpp resource_hook_table.cpp cookie.cpp detail/http_endpoint.cpp detail/body.cpp detail/ip_representation.cpp detail/ip_access_control.cpp detail/ws_registry.cpp detail/hook_bus.cpp detail/route_table.cpp detail/daemon_lifecycle.cpp detail/dispatch_util.cpp detail/error_pages.cpp detail/hook_dispatcher.cpp detail/http_request_impl.cpp detail/http_request_impl_args.cpp detail/http_request_impl_tls.cpp detail/request_dispatcher.cpp detail/request_pipeline.cpp detail/response_materializer.cpp detail/upload_pipeline.cpp detail/websocket_upgrader.cpp detail/webserver_lifecycle.cpp detail/webserver_register.cpp detail/webserver_routes.cpp detail/webserver_routes_upsert.cpp detail/webserver_callbacks.cpp detail/webserver_dispatch.cpp detail/webserver_request.cpp detail/webserver_body_pipeline.cpp detail/webserver_error_pages.cpp detail/webserver_aliases.cpp
28+
libhttpserver_la_SOURCES = string_utilities.cpp webserver.cpp webserver_add_hook.cpp http_utils.cpp file_info.cpp http_request.cpp http_request_auth.cpp http_response.cpp http_response_factories.cpp http_resource.cpp create_webserver.cpp create_test_request.cpp websocket_handler.cpp hook_handle.cpp peer_address.cpp resource_hook_table.cpp cookie.cpp detail/http_endpoint.cpp detail/body.cpp detail/ip_representation.cpp detail/ip_access_control.cpp detail/ws_registry.cpp detail/hook_bus.cpp detail/route_table.cpp detail/daemon_lifecycle.cpp detail/dispatch_util.cpp detail/error_pages.cpp detail/hook_dispatcher.cpp detail/http_request_impl.cpp detail/http_request_impl_args.cpp detail/http_request_impl_tls.cpp detail/request_dispatcher.cpp detail/request_pipeline.cpp detail/response_materializer.cpp detail/upload_pipeline.cpp detail/websocket_upgrader.cpp detail/webserver_lifecycle.cpp detail/webserver_register.cpp detail/webserver_routes.cpp detail/webserver_routes_upsert.cpp detail/webserver_callbacks.cpp detail/webserver_dispatch.cpp detail/webserver_request.cpp detail/webserver_body_pipeline.cpp detail/webserver_aliases.cpp
2929
# noinst_HEADERS: shipped in the tarball but NEVER installed under $prefix/include.
3030
# Detail headers (httpserver/detail/*.hpp) live here so they cannot leak to
3131
# downstream consumers — the public surface comes in through <httpserver.hpp>.

src/detail/webserver_aliases.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include <utility>
6565

6666
#include "httpserver/create_webserver.hpp"
67+
#include "httpserver/detail/dispatch_util.hpp"
6768
#include "httpserver/detail/method_utils.hpp"
6869
#include "httpserver/hook_action.hpp"
6970
#include "httpserver/hook_context.hpp"
@@ -244,12 +245,12 @@ void webserver::install_auth_alias_() {
244245
try {
245246
rejection = ws_ptr->config.auth_handler(*ctx.request);
246247
} catch (const std::exception& e) {
247-
impl_ptr->log_dispatch_error(
248+
detail::log_dispatch_error(ws_ptr->config,
248249
std::string("auth_handler threw: ").append(e.what())
249250
.append("; failing closed with 500"));
250251
auth_threw = true;
251252
} catch (...) {
252-
impl_ptr->log_dispatch_error(
253+
detail::log_dispatch_error(ws_ptr->config,
253254
"auth_handler threw unknown exception; "
254255
"failing closed with 500");
255256
auth_threw = true;

src/detail/webserver_error_pages.cpp

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/httpserver/detail/webserver_impl_dispatch.hpp

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,11 @@
4242

4343
// The 404/405/500 synthesis (not_found_page / method_not_allowed_page /
4444
// internal_error_page / run_internal_error_handler_safely) moved to the
45-
// error_pages behavior service (DR-014 §4.11); its webserver_impl forwarders
46-
// were removed once every caller became a service holding error_pages&
47-
// directly. Only log_dispatch_error survives below, still called from the v1
48-
// alias hooks (webserver_aliases.cpp).
49-
50-
// Log @p msg via parent->config.log_error if a logger is configured.
51-
// Swallows any exception thrown by the logger -- dispatch must never
52-
// re-enter the catch from inside its own catch. Marked noexcept because
53-
// the outer catch(...) absorbs any bad_alloc from std::string(msg)
54-
// construction, so no exception can escape.
55-
//
56-
// @p msg is forwarded to the user
57-
// log_error callback UNCHANGED, regardless of
58-
// create_webserver::expose_exception_messages. The error log is the
59-
// canonical destination for verbatim exception text in v2; the HTTP
60-
// response body is the path that was sanitized. Handlers that may
61-
// throw exceptions containing sensitive data (DB connection strings,
62-
// credentials, attacker-influenced input) SHOULD catch and sanitize
63-
// the exception's what() before re-throwing if those values must not
64-
// appear in the server log either. See also @ref
65-
// internal_error_handler_t @security block in create_webserver.hpp.
66-
void log_dispatch_error(std::string_view msg) const noexcept;
45+
// error_pages behavior service (DR-014 §4.11), and the log_dispatch_error
46+
// member forwarder was removed once its last callers (the v1 alias hooks in
47+
// webserver_aliases.cpp) began calling the detail::log_dispatch_error free
48+
// function (dispatch_util.hpp, over the config bag) directly. No
49+
// webserver_impl error-page or log forwarder survives.
6750

6851
// The lifecycle hook-firing helpers (the eleven per-phase fire_* and the
6952
// four gated fire_*_gated helpers) moved to the hook_dispatcher behavior

0 commit comments

Comments
 (0)