Expand description
Drift-detection middleware for the x-cratestack-schema-sha header
(issue #178). Every generated client stamps its own SCHEMA_SHA256
constant (SHA-256 of the .cstack source it was compiled against)
onto every request; this middleware compares that value against the
server’s own constant and tracing::warn!s on a mismatch — nothing
more. It never rejects a request: a missing header (a client not yet
regenerated) is not itself a warning, and a present-but-different value
only ever produces a log line, never an error response. See
docs/design/protobuf.md-adjacent context: this grew out of the
protobuf/gRPC work but applies to every transport (rest/rpc/grpc
alike), since nothing about schema drift is protobuf-specific.
Deliberately a plain axum::middleware::from_fn_with_state function,
not a hand-rolled tower::Layer/Service pair like
crate::idempotency::IdempotencyLayer or
crate::ratelimit::RateLimitLayer — those exist because they need
async state lookups (a store) and per-request state threading that
justifies the extra structure. This check is “compare a header to a
known string and maybe log,” which from_fn_with_state covers in a
fraction of the code with no loss of correctness.
Constants§
- SCHEMA_
SHA_ HEADER x-cratestack-schema-sha— lowercase per HTTP/2 header-name convention;axum/httpnormalize header name lookups case-insensitively either way, but the constant form is what generated clients literally send.
Functions§
- warn_
on_ schema_ mismatch - Wraps a router with the drift-detection check.
expected_shais the server’s ownSCHEMA_SHA256constant ('static, baked in at macro- expansion time — seecrates/cratestack-macros/src/include/server.rs).