CodeVetter · Repo Unpack · Behavior traces
tokio-rs/axum
The inspected flows span library execution and concrete example applications. Server startup proceeds from application construction to listener acceptance and Hyper connection execution. Request processing includes conditional rejection before business logic, while authentication and persistence examples introduce additional state and network boundaries. These traces describe source execution order; none were exercised at runtime.
- Startup: the key-value main initializes tracing, creates SharedState, composes routes and middleware, supplies state, binds 127.0.0.1:3000, and awaits axum::serve; Serve::run then repeatedly accepts and calls handle_connection.
- Request dispatch: Router::call_with_state calls PathRouter::call_with_state, which matches the path and calls MethodRouter::call_with_state; the selected endpoint becomes a Route, and Handler::call extracts arguments before calling the async function.
- Key-value write/read: POST /{key} selects kv_set with DefaultBodyLimit disabled and a 5,120,000-byte RequestBodyLimitLayer; kv_set inserts bytes, and subsequent GET /{key} uses kv_get's compressed response or 404 branch.
- JWT flow: POST /authorize extracts AuthPayload, rejects empty or incorrect demonstration credentials, creates Claims, encodes a token, and returns AuthBody; GET /protected extracts a Bearer header and decodes Claims with Validation::default before protected runs.
- OAuth initiation: discord_auth creates an identify-scoped authorization URL and random CSRF token, stores the token in MemoryStore, sets a Secure/HttpOnly/SameSite=Lax session cookie, and redirects to Discord.
- OAuth callback: login_authorized calls csrf_token_validation_workflow, which loads and destroys the old session before comparing state; it then exchanges the code, fetches Discord user JSON, stores a new user session, sets its cookie, and redirects home.
- Persistence startup/action: Diesel main builds a pool and runs embedded pending migrations before binding; POST /user/create invokes create_user's insert-and-return path, while GET /user/list loads Users through another interact closure.
- Graceful shutdown: the signal task drops signal_tx, the accept loop exits on channel closure, connection tasks call Hyper graceful_shutdown, and the server waits for close_tx.closed(); a connection age limit can separately initiate shutdown and enforce a grace deadline.