Repository navigation
fix(parser): make Method::new case-sensitive per RFC 9110 §9.1 - #1474
Merged
Merged
Conversation
`Method::new` compared with `compare_no_case`, so a request line reading `get /path HTTP/1.1` produced `Method::Get`. RFC 9110 §9.1 makes the method token case-sensitive and the origin receives the original `get` bytes, so sozu and the backend could disagree about what method a request carries. Long harmless, made load-bearing by the stale-upstream replay (#1442): `is_idempotent` gates whether a request already written to a pooled upstream may be replayed on a fresh one, and `Method::Custom` is deliberately not idempotent. A lowercase `get` was therefore judged replayable while the origin was free to treat the token as an extension method with side effects of its own. The narrow scoping is not available: `context.method` is already normalised by the time the replay decision runs, and the raw token is gone. The match is now exact against the eight canonical spellings; anything else is `Method::Custom`, carrying the token verbatim. No case-insensitive fallback and no alias table: either would reintroduce the same divergence in a form that is harder to see. Metric cardinality was measured before changing, not after. No metric key or label is derived from the method: the `http.status.*` keys come only from `context.status: u16` through a closed eighteen-code list plus buckets, and the only labels the emission sites pass are `cluster_id` and `backend_id`, both operator-declared. A peer cannot mint label values by varying case, before or after this change. Routing cuts both ways, because `MethodRule::new` classifies a frontend's declared `method` through the same `Method::new`. A frontend declared without a `method` is unaffected. A frontend declared `method = "GET"` no longer matches a client sending `get`; symmetrically one declared `method = "get"` stops answering canonical `GET` requests, so a method declared in non-canonical case must be corrected to the case the client sends. Response framing changes in the direction worth having. `Method::Head` is what terminates the response parse after the headers, and `head` no longer reaches that arm. Before, an RFC-conforming origin answering `405` with a body left that body unread on a pooled keep-alive upstream, desyncing the next request on it — the common pairing. After, the cost lands only on the rare non-conforming pairing, a case-folding origin answering `head` bodiless with a `Content-Length`, where sozu serves 504 at `configured_backend_timeout`: a bounded stall, not a hang. Two smaller consequences: the access log echoes the token verbatim, as it already did for every custom method, and `Method`'s `Debug` now renders a lowercase verb as `Custom(bytes=N)` at the three sites that print `context.method` with `{method:?}`. `doc/configure.md` documented the old lenient behaviour explicitly, in both the routing-rule and replay-eligibility sections, and is updated alongside `mux/LIFECYCLE.md`, the `RequestHttpFrontend.method` proto field and the `--method` CLI help. Closes #1451. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 23, 2026 15:57
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 23, 2026
`check_doc_citations.py` resolves `doc/**` and `**/LIFECYCLE.md`, so a `path.rs:NNN` inside a `//`, `///` or `//!` comment was read by no rule at all — not the existence floor, not the drift comparison, not once. The two `SAFETY:` comments justifying `from_utf8_unchecked` in `lib/src/http.rs` and `lib/src/https.rs` are how it surfaced (#1473): both cited a `Method` match arm for `hostname_and_port`, and drifted there with CI green throughout, until #1474 re-pointed them at the function. The population was measured before the form was chosen, at main `19fd5d8c`: 90 citation tokens across 29 files, holding 113 line targets. Sixty-eight of the 90 had drifted from the text they named at the commit that last wrote or re-anchored them, and only 16 still land on a line that is neither a bare delimiter, a blank, nor past end-of-file. The half-life decided it: 43 of those 68 broke on the very NEXT commit that touched the file they point into, the median citation survived ONE such commit and zero days, and 65 of 68 were wrong inside a week. All 18 `h2.rs:NNN` tokens had drifted. Extending the resolver over `**/*.rs` was the alternative, and it was measured rather than argued: switched on at that revision it would have had to reject those 68, plus 14 naming a basename that is ambiguous here — four files are called `h2.rs`, nineteen `mod.rs` — plus two pointing into the `kawa` dependency, which is not in this repository. A gate that fails on most of the population it guards gets bypassed rather than satisfied, which is the argument the script's own header makes about `--all-features`. So `doc/README.md`'s three forms now govern Rust comments too, with one narrowing: the symbol form only, and a comment that means one branch names that branch in words. All 82 citations outside `lib/src/protocol/mux/` are converted, across 25 files, each re-pointed at the symbol recovered by reading the cited file AT THE COMMIT THAT WROTE THE CITATION rather than at HEAD. The rule is also in `CLAUDE.md`'s code-style list. Rewrapping the comments shifted lines in `e2e/src/tests/h2_correctness_tests.rs`, and the drift rule caught two `doc/testing.md` citations pointing into it — the guarded half of exactly the pair #1465 was about. They now name `try_h2_large_gzipped_chunked_drains_fully` and `try_h2_large_chunked_7mb_drains_fully`. Two corrections fell out of recovering intent rather than trusting HEAD: `h2_log_context_tests.rs` named `log_context_lite!` for a line that is inside `log_module_context!` — only the latter renders the bare `MUX-H2` tag the comment claims — and `e2e/src/tests/mod.rs` named two tests by a line holding their `#[serial_test::serial]` attribute. Comments and documentation only; no code, literal, attribute, assertion or test name changed. The eight sites under `lib/src/protocol/mux/` are left for a separate pass to keep this off a module under concurrent change; two of them, into pinned `kawa` 0.7.1, are the one class here where a line number genuinely cannot rot. Refs #1473 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 23, 2026
`check_doc_citations.py` resolves `doc/**` and `**/LIFECYCLE.md`, so a `path.rs:NNN` inside a `//`, `///` or `//!` comment was read by no rule at all — not the existence floor, not the drift comparison, not once. The two `SAFETY:` comments justifying `from_utf8_unchecked` in `lib/src/http.rs` and `lib/src/https.rs` are how it surfaced (#1473): both cited a `Method` match arm for `hostname_and_port`, and drifted there with CI green throughout, until #1474 re-pointed them at the function. The population was measured before the form was chosen, at main `19fd5d8c`: 90 citation tokens across 29 files, holding 113 line targets. Sixty-eight of the 90 had drifted from the text they named at the commit that last wrote or re-anchored them, and only 16 still land on a line that is neither a bare delimiter, a blank, nor past end-of-file. The half-life decided it: 43 of those 68 broke on the very NEXT commit that touched the file they point into, the median citation survived ONE such commit and zero days, and 65 of 68 were wrong inside a week. All 18 `h2.rs:NNN` tokens had drifted. Extending the resolver over `**/*.rs` was the alternative, and it was measured rather than argued: switched on at that revision it would have had to reject those 68, plus 14 naming a basename that is ambiguous here — four files are called `h2.rs`, nineteen `mod.rs` — plus two pointing into the `kawa` dependency, which is not in this repository. A gate that fails on most of the population it guards gets bypassed rather than satisfied, which is the argument the script's own header makes about `--all-features`. So `doc/README.md`'s three forms now govern Rust comments too, with one narrowing: the symbol form only, and a comment that means one branch names that branch in words. All 82 citations outside `lib/src/protocol/mux/` are converted, across 25 files, each re-pointed at the symbol recovered by reading the cited file AT THE COMMIT THAT WROTE THE CITATION rather than at HEAD. The rule is also in `CLAUDE.md`'s code-style list. Rewrapping the comments shifted lines in `e2e/src/tests/h2_correctness_tests.rs`, and the drift rule caught two `doc/testing.md` citations pointing into it — the guarded half of exactly the pair #1465 was about. They now name `try_h2_large_gzipped_chunked_drains_fully` and `try_h2_large_chunked_7mb_drains_fully`. Two corrections fell out of recovering intent rather than trusting HEAD: `h2_log_context_tests.rs` named `log_context_lite!` for a line that is inside `log_module_context!` — only the latter renders the bare `MUX-H2` tag the comment claims — and `e2e/src/tests/mod.rs` named two tests by a line holding their `#[serial_test::serial]` attribute. Comments and documentation only; no code, literal, attribute, assertion or test name changed. The eight sites under `lib/src/protocol/mux/` are left for a separate pass to keep this off a module under concurrent change; two of them, into pinned `kawa` 0.7.1, are the one class here where a line number genuinely cannot rot. Refs #1473 Signed-off-by: Florentin Dubois <[email protected]>
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.
Method::newusedcompare_no_case, so a request line readingget /path HTTP/1.1producedMethod::Get. RFC 9110 §9.1 makes the method token case-sensitive, and the origin receives the originalgetbytes — so sozu and the backend could disagree about what method a request carries.Long harmless, until
is_idempotentbegan gating whether a request may be replayed on a fresh backend. A lowercase extension verb that sozu mapped to an idempotent variant became replayable while the origin was free to give it side effects of its own.The gate that decided this could ship
The obvious risk of making the parser strict is metric cardinality: if
Method::Custom(String)reaches a metrics label, a peer mints unbounded label values by varying case, and a correctness fix becomes a memory-growth vector. The lenient behaviour might have been what collapsed them.It is not, and the reason is structural rather than incidental. Every
incr!/count!/gauge!/time!/record_*inlib/,bin/andcommand/funnels throughSubscriber::receive_metric(lib/src/metrics/mod.rs:322),count_add(:847),set_gauge(:851) andgauge_add(:855) — every one typedkey: &'static str.Method::Custom(String)is heap-allocated and cannot coerce; there is noleak(), notransmute, noOnceLock<String>anywhere inlib/src,bin/srcorcommand/src.http_status_code_metric_name(metrics/mod.rs:87-107) is a closed 18-codeu16match with_ => None. The only runtime label strings arecluster_idandbackend_id, both operator-declared. OpenTelemetry is a separate path and carries only fixed-width trace and span ids (command/src/logging/access_logs.rs:134) — no span name, no attribute map, no method field.A peer cannot mint a metric series by varying case, before or after this change.
Four observable consequences
MethodRule::new(lib/src/router/mod.rs:1450) classifies the frontend's declared method through the sameMethod::new, andmatchesis a plain==. A frontend declaringmethod = "GET"no longer matches a client sendingget(builtin 404); symmetrically,method = "get"stops answering canonicalGET. Silent-never-match was already the documented failure mode for unrecognised methods — this extends it to known verbs, which is why the case note now lives atcommand/src/command.proto:874and inbin/src/cli.rs's help, next to where an operator writes the value.getis logged asgetrather thanGET(lib/src/protocol/mux/stream.rs:721), i.e. what the client actually sent. Already verbatim for every custom method.Method::Headterminates the response parse atlib/src/protocol/kawa_h1/editor.rs:1117andlib/src/protocol/mux/h2.rs:4674. A client sendingheadno longer hits that arm. Before,head→Method::Head→ terminate-after-headers, so an RFC-conforming origin answering405with a body left unread bytes on a pooled keep-alive upstream — a desync, against the common case. After, framing followsContent-Length; against a case-folding origin answering HEAD-style, sozu waits for a body that never arrives and serves 504 atconfigured_backend_timeout(lib/src/protocol/mux/mod.rs:1521,:2185-2186) — a bounded stall holding one session and one backend connection, against the rare case. A desync against conforming origins is traded for a bounded 504 against non-conforming ones.A fifth, non-observable to operators: debug logs render
context.methodthrough{method:?}atlib/src/protocol/mux/mod.rs:129,:1192andlib/src/protocol/mux/router.rs:65, andMethod'sDebugredacts custom methods toCustom(bytes=N)(kawa_h1/parser.rs:61). Somethod=Some(Get)becomesmethod=Some(Custom(bytes=3))— for exactly the population an operator will be debugging after this change. Recorded in the CHANGELOG rather than changed, since the redaction is deliberate.Tests
Three added; two are falsifiable by reverting the
Method::newbody, and the third is honestly labelled:lowercase_verb_is_custom_and_not_idempotentparser.rs:390,left: Get, right: Custom(bytes=3)method_rule_is_case_sensitiverouter/mod.rs:2476,left: Some(Get), right: Some(Custom(bytes=3))canonical_verbs_keep_their_variantNot test-shaped: the tests' lowercase literals appear zero times in the production hunk, and all eight uppercase literals the fix uses already existed on
mainascompare_no_casearguments.Methodhas exactly eight non-Customvariants and the tests cover all eight, so there is no ninth-verb gap.What was deliberately not done
No case-insensitive fallback and no alias table preserving today's behaviour for known verbs — the issue rules that out by name, and it would reintroduce the divergence in a form harder to see. No load-time warning or validation on a declared method either; that is scope #1451 did not ask for, and it is worth noting that
methodis now the only case-sensitive string in a config file whose siblings fold (parse_redirect_policyandparse_redirect_schemeboth document "(case-insensitive)").Sweep
No fixture, e2e test, fuzz seed, doc example, TOML or JSON asset anywhere in
e2e/,lib/,bin/,command/,fuzz/,doc/orexamples/declares a non-canonical method literal. H1 e2e request lines are uppercase; H2 e2e uses static-table0x82/0x83; the HPACK corpus holds indexed references, not literals. The H2 path converges on the same classifier with no H2-local normalization:pkawa.rs:827folds the pseudo-header name,:831validates the value againstis_tcharonly,:835stores it verbatim.One pre-existing disagreement closes for free:
pkawa.rs:1011-1013gated the:path *asterisk form on a rawm == b"OPTIONS"compare, already case-sensitive, so:method options+:path *was rejected whileMethod::newcalled itMethod::Options. They now agree.Also corrected here, both found by review:
doc/configure_admin_ops.mdcitedconfigure.md:2998forhttps.alpn.rejected.unsupported, ~26 lines off and in a line this branch shifted; and the twoSAFETY:comments atlib/src/http.rs:849andlib/src/https.rs:1242citedparser.rs:133forhostname_and_port, which is at:182. The policy question those raise — thatfile:linecitations in Rust comments are outside the CI gate's scope entirely — is filed as #1473.Closes #1451