Пример
axum 0.8.9: Test axum handlers and routing without binding a port by driving the whole Router through tower's ServiceExt::oneshot, and get the exact status for each way a request can be wrong
Проверенный пример — cargo axum 0.8.9: Test axum handlers and routing without binding a port by driving the whole Router through tower's ServiceExt::oneshot…
sha256:ad2f9d5347cb52c3acc083de3c1608225248a42c41031bf843e1163d738b6e70
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 2
- Ключи подписи, собравшие его
- 2
Заявленная среда
rust 1 linux x64 rust 1 rust cargo
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| rust 1 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1 |
2026-08-14 |
| rust 1 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1 |
2026-08-18 |
Кейс
HOW- Цель
- Test axum handlers and routing without binding a port by driving the whole Router through tower's ServiceExt::oneshot, and get the exact status for each way a request can be wrong
- Символы
-
- tower::ServiceExt::oneshot
- axum::Router::route
- axum::Router::with_state
- axum::extract::Path
- axum::extract::Query
- axum::extract::State
- axum::Json
- axum::body::Body
- http_body_util::BodyExt::collect
- axum::debug_handler
- Окружение
- rust 1
- Создан
- 2026-08-14T13:27:02Z
Контракт
- assert a GET driven through the Router by oneshot returns 200 with the exact JSON body that the Path and State extractors produce, with no listener and no port
- assert axum's Json response sets a bare application/json content-type with no charset parameter
- assert its content-length equals the length of the collected body
- assert HEAD on a GET route returns 200 with an empty body and still reports the content-length a GET would have sent
- assert a well-formed POST body reaches the handler and returns 201 with the handler's JSON
- assert syntactically broken JSON is 400 BAD REQUEST, not 422, and carries the parse error with the serde field path in it
- assert that rejection body is text/plain rather than JSON
- assert JSON that parses but has the wrong type for a field is 422 UNPROCESSABLE ENTITY with the deserialize message
- assert a missing required field is the same 422
- assert a request with no Content-Type is 415 UNSUPPORTED MEDIA TYPE carrying the rejection message rather than the handler's 201
- assert the Content-Type check accepts a charset parameter and an application/...+json vendor type but refuses text/json exactly like a missing header
- assert an unmatched route is 404 with an empty body and no response headers at all, not even content-length
- assert a wrong method on a matched path is 405 with Allow: GET,HEAD and content-length 0
- assert Allow describes the matched route rather than the router, listing only POST for a POST-only path
- assert OPTIONS is not handled for you and gets the same 405
- assert extractors before the body run in argument order, so two handlers differing only in Path before Query answer the same broken request with different rejections
- assert the body extractor's own rejection only appears once every extractor ahead of it succeeded
- assert a handler with State before Json compiles clean
- assert swapping them fails with E0277 on Handler, with the span on the route() registration and nothing pointing at the handler's own line, and with the message never containing "body", "order" or "last argument"
- assert that error's one suggestion is the note recommending #[axum::debug_handler] and that it offers nothing else, carrying no help: line at all
- assert #[axum::debug_handler] on the same handler leads with an error naming the rule that Json consumes the body and must be the last argument, underlining that argument in the handler's signature
- assert axum 0.8 panics while building a Router from the 0.7 ":id" capture syntax, naming {capture} as the replacement
- assert "*path" panics the same way, naming {*wildcard}
- assert the {id} and {*path} spellings build
Файлы
- Cargo.lock
- Cargo.toml
- csx.json
- rustc_probe/json_then_state.rs
- rustc_probe/json_then_state_debug.rs
- rustc_probe/state_then_json.rs
- src/main.rs