CodeVetter · Repo Unpack · Data flow
tokio-rs/axum
Incoming connections are converted into per-connection services, and incoming HTTP bodies are normalized before routing. Path matching enriches request extensions, method dispatch selects an endpoint, and handler adapters construct typed arguments in sequence. Response conversion provides the common output boundary for successful values and rejections. Durable data, session storage, and file writes are owned by example applications rather than the routing library.
- handle_connection waits for make_service readiness, calls it with IncomingStream, maps Hyper Incoming bodies into axum Body, and wraps the resulting Tower service with TowerToHyperService.
- PathRouter preserves OriginalUri when enabled, matches uri.path(), installs MatchedPath and URL parameters, then dispatches the indexed endpoint; a missing path returns the request and state to Router's fallback.
- Handler::call splits the request, extracts all preceding arguments from mutable Parts, reconstructs the request for the last extractor, and returns immediately on any rejection before invoking the handler.
- Json extraction validates content type, delegates buffering to Bytes::from_request, deserializes with serde_path_to_error, and calls deserializer.end() to reject trailing data.
- State<InnerState> derives application substates through FromRef<OuterState>; Router::with_state distributes supplied state to its path router and catch-all fallback.
- The key-value example transforms a path capture and body bytes into a HashMap insertion under a write lock; reads clone stored Bytes under a read lock and return 404 when absent.
- Diesel create_user deserializes NewUser, acquires a pooled connection, inserts values inside interact, retrieves the returned User, and serializes it as Json; the migration defines the corresponding users table.
- PrivateCookieJar obtains a key from state, retains only successfully decrypted request cookies, and writes jar changes into response headers through IntoResponseParts.