Expand description
Bearer-key authentication and per-request metering (Phase 2 design §4, §5).
This module is the only place a secret is ever visible: handlers receive a
KeyId and nothing else, so a handler cannot leak a secret by accident
and the metering layer has a stable identity to record without touching the
credential.
Order of operations per request:
- Read
Authorizationand require the exact formBearer <key_id>:<secret>. - Verify against the in-memory
KeyStorein constant time. - On success, attach
KeyIdto the request extensions. - Run the inner service.
- Measure the response body and append exactly one metering record.
A rejected request (step 1 or 2) is answered 401 and is not metered. See
the deviation note in crate::metering.
Structs§
- Auth
Metering - Everything the auth + metering layer needs, shared by reference.
- KeyId
- The authenticated
key_id, attached to the request by [auth_and_meter].
Constants§
- MAX_
RESPONSE_ BYTES - Largest response body the middleware will buffer in order to measure it.
Functions§
- metered
- Wraps
routerso every route requires a bearer key and is metered.