refactor(dpi/http): drop dead inner parts.len() >= 3 check#303
Merged
domcyrus merged 1 commit intoMay 21, 2026
Merged
Conversation
`analyze_http` gates first-line parsing on `parts.len() >= 3` and then
re-checks the same condition inside the request branch:
if parts.len() >= 3 {
...
} else if is_http_method(parts[0]) {
info.method = Some(parts[0].to_string());
info.path = Some(parts[1].to_string());
if parts.len() >= 3 {
info.version = parse_http_version(parts[2]);
}
...
}
`parts` is not mutated between the outer and inner check, so the inner
gate is always true and `parse_http_version(parts[2])` runs
unconditionally. Drop the inner `if` and call it directly; expand the
comment to record the invariant the outer guard provides.
Behavior is unchanged.
Refs domcyrus#302
Owner
|
@obchain Thanks a lot for your PR, LGTM! |
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.
Summary
analyze_http(src/network/dpi/http.rs) gates first-line parsing onparts.len() >= 3and then re-checks the same condition inside the request branch:partsis not mutated between the outer guard (line 30) and the inner check (line 39), so the innerifis always true andparse_http_version(parts[2])runs unconditionally. Drop the inner conditional and call the function directly; the expanded comment records the invariant the outer guard provides so a future reader doesn't reintroduce the check.Behavior is unchanged.
Closes #302.
Verification
cargo test --lib: all pass (4 innetwork::dpi::http/https).cargo clippy --all-targets -- -D warnings: clean.cargo fmt --check: clean.Notes
Fits the recent
refactor(dpi/...)cleanup series — same shape as #296 (sshdead conditional) and #279 (snmpunreachable arm). Net diff is 3 added / 4 removed in a single block; no test churn since both code paths through the request branch are already exercised bytest_http_request.