Repository navigation
Extract file-serving Range parser below the cognitive-complexity cap - #8561
Merged
Amaury Chamayou (achamayou) merged 4 commits intoOct 16, 2026
Merged
Conversation
Preserve Range parsing and response behavior while reducing cognitive complexity below the existing cap. Add parser and caller regression coverage to node_frontend_test. Refs #7358 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This was referenced Oct 16, 2026
Resolve conflicts with #8214: apply the parser extraction to the templated fill_range_response and drop the test assertions on stream open/close state, since stream lifetime now belongs to the caller. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused extraction preserves existing behavior with no identified blocking issues; required CI must pass on the current head.
0 open findings
What changed in this PR
Extracts Range-header parsing from CCF’s file-serving response helper to meet the cognitive-complexity limit while preserving existing behavior.
Changes:
- Introduces a parser returning half-open bounds or an owned error message.
- Centralizes parser-error responses and removes the complexity suppression.
- Adds regression coverage for parsing boundaries, GET/HEAD responses, digests, and conditional requests.
Custom instructions used
Applied the supplied CCF repository and security/safety guidance; instruction files were unavailable locally.
| File | Description |
|---|---|
| src/node/rpc/test/node_frontend_test.cpp | Adds parser and response regression tests. |
| src/node/rpc/file_serving_handlers.h | Extracts parsing and removes the complexity suppression. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Max (maxtropets)
approved these changes
Oct 16, 2026
Amaury Chamayou (achamayou)
enabled auto-merge (squash)
October 16, 2026 10:46
Amaury Chamayou (achamayou)
deleted the
achamayou-range-parser-extraction
branch
October 16, 2026 11:04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The file-serving range helper scores 69 on
readability-function-cognitive-complexity, against a threshold of 50, and carries a baseline suppression. Most of the complexity is Range-header parsing. This PR extracts the parser so the suppression can be removed without changing behaviour.Related to #7358. The remaining suppressions are handled in #8560 and #8562.
Implementation summary
Move the parsing statements into
detail::parse_range_header, which returns either a half-openFileRangeor an owned error message. The caller keeps Range-header discovery, the singleInvalidHeaderValueerror response, and empty-range rejection. Every error message, clamping rule, and debug log is preserved; the nineset_errorsites collapse into one at the call site.Add
node_frontend_testcases for parser error messages, malformed and overflowing inputs, accepted numeric prefixes and trailing text, open, suffix, and clamped ranges,SIZE_MAXboundaries, GET/HEAD metadata and body handling, and digest and conditional-request ordering.Since #8214 landed on
main, the caller is the templatedfill_range_response; the extraction applies there unchanged. The new tests no longer assert on stream open/close state, since #8214 moved stream lifetime to the caller.Measured with clang-tidy 21.1.8 and
IgnoreMacros=true; the repository threshold stays at 50:fill_range_responsedetail::parse_range_headerSafety and compatibility
Internal refactor with no API or data-format impact. A token comparison against the base shows the only differences are the eight removed
set_errorprefixes,range_header.value()becoming theconst std::string¶meter, and thevariantplumbing. Inclusive-end clamping before increment, suffix clamping before subtraction, and the non-zero-size precondition are unchanged. No view escapes the parser; error messages are owned strings.Validation:
node_frontend_teston the merged tree and ran it; all cases pass, including the new ones.scripts/ci-checks.shpassed without auto-fix.CLANG_TIDY=ONbuild with the suppression removed. Required CI must pass again on the current head.