Skip to main content

Module schema_fingerprint

Module schema_fingerprint 

Source
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/http normalize 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_sha is the server’s own SCHEMA_SHA256 constant ('static, baked in at macro- expansion time — see crates/cratestack-macros/src/include/server.rs).