CodeSampleX

샘플

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, and get the…

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

컨트랙트

  1. 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
  2. assert axum's Json response sets a bare application/json content-type with no charset parameter
  3. assert its content-length equals the length of the collected body
  4. assert HEAD on a GET route returns 200 with an empty body and still reports the content-length a GET would have sent
  5. assert a well-formed POST body reaches the handler and returns 201 with the handler's JSON
  6. assert syntactically broken JSON is 400 BAD REQUEST, not 422, and carries the parse error with the serde field path in it
  7. assert that rejection body is text/plain rather than JSON
  8. assert JSON that parses but has the wrong type for a field is 422 UNPROCESSABLE ENTITY with the deserialize message
  9. assert a missing required field is the same 422
  10. assert a request with no Content-Type is 415 UNSUPPORTED MEDIA TYPE carrying the rejection message rather than the handler's 201
  11. assert the Content-Type check accepts a charset parameter and an application/...+json vendor type but refuses text/json exactly like a missing header
  12. assert an unmatched route is 404 with an empty body and no response headers at all, not even content-length
  13. assert a wrong method on a matched path is 405 with Allow: GET,HEAD and content-length 0
  14. assert Allow describes the matched route rather than the router, listing only POST for a POST-only path
  15. assert OPTIONS is not handled for you and gets the same 405
  16. 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
  17. assert the body extractor's own rejection only appears once every extractor ahead of it succeeded
  18. assert a handler with State before Json compiles clean
  19. 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"
  20. 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
  21. 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
  22. assert axum 0.8 panics while building a Router from the 0.7 ":id" capture syntax, naming {capture} as the replacement
  23. assert "*path" panics the same way, naming {*wildcard}
  24. 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

소스 아티팩트 내려받기 (tar.gz)

오리진 시더

anonymous