Skip to content

core(http): route dispatch in four chains (MSVC nesting limit) - #2362

Merged
frstrtr merged 1 commit into
masterfrom
core/http-route-chain-msvc
Nov 28, 2026
Merged

frstrtr merged 1 commit into
masterfrom
core/http-route-chain-msvc

Conversation

@frstrtr

@frstrtr frstrtr commented Nov 28, 2026

Copy link
Copy Markdown
Owner

One commit, src/core/http_session.cpp only. Responses are unchanged.

  • Why. HttpSession::process_request matched its REST routes with one else-if chain of 87 branches (nesting 111). MSVC stops at about 128 nested blocks (C1061, as in ltc: command-line parsing under the MSVC nesting limit (Windows build) #2361), so about 17 more routes would have broken the Windows build.
  • Change. The chain is split into four chains (27, 27, 25 and 9 branches), joined by a route_matched flag, the pattern main_dash.cpp uses.
    • Most branches set rest_result / response_body and fall through to the shared response code after the chain, so the split keeps that code path as it was.
    • The fourth chain keeps the original final else: admin, explorer, static files, 404 and the getinfo fallback.
    • Route order, conditions, the guards before the chain and the code after it are unchanged. A token diff against master (comments excluded) adds only the route_matched tokens and three braces.
  • After: longest else-if chain 26; deepest nesting in process_request 37.

Checks (Release)

  • Old vs new responses, compared byte for byte by a temporary harness (not committed) on three local servers: every function wired, nothing wired, and token/CORS/not-ready.
    • Requests: every route on the web and stratum ports with GET and HEAD, prefix, bad-parameter, unknown, static and traversal variants, X-Forwarded-For, token and If-None-Match cases, other methods, and POST bodies.
    • 3624 requests: 3602 byte-identical; the other 22 differ only in time fields (timestamp, computed_at, ts, started). They are identical once those fields are masked, and two runs of the old binary differ in exactly the same 22.
  • core_test HTTP/web/stratum-HTTP suites: 278 passed on both binaries; full core_test 870 passed.

HttpSession::process_request matched its REST routes with one else-if
chain: 88 branches, 87 else-if, nesting 111. MSVC stops at 128 (C1061,
"blocks nested too deeply").

- The chain is now four consecutive else-if chains of 27, 27, 25 and 9
  branches, joined by a route_matched flag (the main_dash.cpp pattern).
- The first three chains end in `else route_matched = false;`. Each later
  chain runs only while route_matched is false.
- The routes are tried in the same order. The last chain keeps the old
  final else: admin, explorer, static files, getinfo.
- The code after the chain is unchanged.
- Token diff against master, comments excluded: only the route_matched
  tokens are added. Chains 2-4 are indented 4 more spaces.
- Longest else-if chain in process_request: 26 (was 87). Deepest
  nesting: 37 (was 111).
Comment thread src/core/http_session.cpp
try {
decoded.push_back(static_cast<char>(
std::stoi(hex, nullptr, 16)));
i += 2;
Comment thread src/core/http_session.cpp

std::string ep = target.substr(16); // after "/api/admin/pool/"
// strip query string
auto qpos = ep.find('?');
Comment thread src/core/http_session.cpp
{"code", "BAD_PARAMS"},
{"method", ep}};
std::string ep = target.substr(16); // after "/api/admin/coin/"
auto qpos = ep.find('?');
@frstrtr
frstrtr merged commit ed7c27c into master Nov 28, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants