샘플
Protect axum routes with stateful middleware using from_fn_with_state, isolate route_layer from 404 fallbacks, and manage bottom-to-top layer execution order
sha256:0add9e86ea54fb151285ed7fff0ac6a073835d84159f6bfc43b6e447f030a7be
PUBLISHED
L3_CONTRACT_PASS
MIT-0
케이스
- 목표
- Protect axum routes with stateful middleware using from_fn_with_state, isolate route_layer from 404 fallbacks, and manage bottom-to-top layer execution order HOW
- 패키지
- axum 0.8.9 tower 0.5.3 http-body-util 0.1.5 tokio 1.53.1
- 환경
- rust
- 생성일
- 2026-08-16T08:11:01Z
컨트랙트
- assert route_layer protects routes registered before it, returning 200 with typed Extension and injected headers when authorization token is valid
- assert route_layer rejects unauthorized requests with 401 and custom error headers without invoking the route handler
- assert route_layer leaves public routes registered after it unprotected, returning 200 without executing the auth middleware or incrementing state call counter
- assert an unmatched 404 route on a route_layer router returns 404 Not Found without invoking auth middleware
- assert Router::layer wraps the entire router including 404 fallbacks, returning 401 Unauthorized for unmatched paths when authorization is absent
- assert an unpopulated Extension extractor fails dynamically at runtime with 500 Internal Server Error when the route is not wrapped by the populating middleware
- assert chained layers execute in reverse registration order (bottom-to-top): outer layer runs before inner layer on request, and inner layer runs before outer layer on response
- assert sub-router route_layer middleware is isolated to the nested prefix and does not run on parent router routes
파일
- Cargo.lock
- Cargo.toml
- NOTES.md
- csx.json
- src/lib.rs
- tests/middleware_tests.rs
검증된 아티팩트 내려받기 (tar.gz) — 컨트랙트가 실제로 실행된 바로 그 바이트
오리진 시더
검증 영수증
- rust 1 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · cargo@1 · 2026-08-16 · ed25519:d91480838ac982c9