CodeSampleX

샘플

hyper 1.12.0: hyper::Method, hyper::Request, hyper::Response

검증된 샘플 — cargo hyper 1.12.0: hyper::Method, hyper::Request, hyper::Response. rust 1 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다.

sha256:24cc8c0b37bcfa64c2812bdf8d7faa9043c6f0e4747e5ebce4ed0e36fa5691d6

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 rust linux x64 rust rust cargo

검증 실행 환경

환경 컨트랙트 단계 실행일
rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b…
2026-11-07

케이스

HOW
목표
verify pkg:cargo/hyper@1.12.0
패키지
심벌
  • hyper::Method
  • hyper::Request
  • hyper::Response
  • hyper::StatusCode
  • hyper::service::service_fn
환경
rust
생성일
2026-11-07T07:50:58Z

컨트랙트

  1. assert hyper::Request::builder constructs GET, POST, and DELETE requests with method, URI, HTTP/1.1 version, and string body
  2. assert hyper::service::service_fn wraps a request handler and Service::call returns a future resolving to hyper::Response
  3. assert hyper::Response::builder sets StatusCode (OK, CREATED, NOT_FOUND), Version::HTTP_11, and CONTENT_TYPE header

파일

  • Cargo.lock
  • Cargo.toml
  • NOTES.md
  • PROMPT.md
  • csx.json
  • spec.json
  • src/main.rs

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

소스

Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "bytes"
version = "1.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"

[[package]]
name = "http"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0"
dependencies = [
 "bytes",
 "itoa",
]

[[package]]
name = "http-body"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c"
dependencies = [
 "bytes",
 "http",
]

[[package]]
name = "hyper"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c3e324da4c95177d6291d4c8730197c0d1822f8a9766814a4a44fa5ab797c9c"
dependencies = [
 "bytes",
 "http",
 "http-body",
 "tokio",
]

[[package]]
name = "itoa"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"

[[package]]
name = "pin-project-lite"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"

[[package]]
name = "sample-hyper"
version = "0.1.0"
dependencies = [
 "hyper",
]

[[package]]
name = "tokio"
version = "1.54.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b52fd3255258d26fac7264ab5a76b53c13367136dc011d3d6ad4f8ed070396a3"
dependencies = [
 "pin-project-lite",
]
Cargo.toml
[package]
name = "sample-hyper"
version = "0.1.0"
edition = "2021"

[dependencies]
hyper = "=1.12.0"
NOTES.md
### Search Result
`search_known_solution` returned `NO_SAFE_MATCH` for `pkg:cargo/hyper@1.12.0`.

### Implementation Notes
`hyper@1.12.0` provides core HTTP types (`Request`, `Response`, `Method`, `StatusCode`, `Version`, `header`) and the `Service` / `service_fn` abstraction without requiring feature flags when constructing and invoking in-memory HTTP services.
PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:cargo/hyper@1.12.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/hyper@1.12.0

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:2dac85d9553ffefe1432bce13926e8afff55c8d407e52b11e7c30898170be9c2","contract":["assert hyper::Request::builder constructs GET, POST, and DELETE requests with method, URI, HTTP/1.1 version, and string body","assert hyper::service::service_fn wraps a request handler and Service::call returns a future resolving to hyper::Response","assert hyper::Response::builder sets StatusCode (OK, CREATED, NOT_FOUND), Version::HTTP_11, and CONTENT_TYPE header"],"goal":"verify pkg:cargo/hyper@1.12.0","kind":"HOW","packages":["pkg:cargo/hyper@1.12.0"],"schemaVersion":1,"symbols":["hyper::Method","hyper::Request","hyper::Response","hyper::StatusCode","hyper::service::service_fn"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","executionContext":"rust","language":"rust","os":"linux","packageManager":"cargo","runtime":"rust","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/hyper@1.12.0"],"schemaVersion":1,"subject":"pkg:cargo/hyper@1.12.0","symbols":["hyper::Method","hyper::Request","hyper::Response","hyper::StatusCode","hyper::service::service_fn"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/hyper@1.12.0",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/hyper@1.12.0"
  ]
}
src/main.rs
use std::convert::Infallible;
use std::future::{ ready, Future, Ready };
use hyper::body::{ Body, Frame };
use hyper::header::{ HeaderValue, CONTENT_TYPE };
use hyper::service::{ service_fn, Service };
use hyper::{ Method, Request, Response, StatusCode, Version };

fn handle_request(req: Request<String>) -> Ready<Result<Response<String>, Infallible>> {
    let method = req.method().clone();
    let path = req.uri().path().to_string();
    let body = req.into_body();

    let (status, resp_body) = match (method, path.as_str()) {
        (Method::GET, "/health") => (StatusCode::OK, "ok".to_string()),
        (Method::POST, "/echo") => (StatusCode::CREATED, format!("echo:{}", body)),
        _ => (StatusCode::NOT_FOUND, "not found".to_string()),
    };

    let mut resp = Response::builder()
        .status(status)
        .version(Version::HTTP_11)
        .body(resp_body)
        .expect("valid response");
    resp.headers_mut().insert(
        CONTENT_TYPE,
        HeaderValue::from_static("text/plain; charset=utf-8")
    );
    ready(Ok(resp))
}

fn poll_ready_future<F: Future>(fut: F) -> F::Output {
    use std::pin::Pin;
    use std::task::{ Context, Poll, RawWaker, RawWakerVTable, Waker };

    fn noop_clone(_: *const ()) -> RawWaker {
        RawWaker::new(std::ptr::null(), &VTABLE)
    }
    fn noop(_: *const ()) {}
    static VTABLE: RawWakerVTable = RawWakerVTable::new(noop_clone, noop, noop, noop);

    let waker = unsafe { Waker::from_raw(RawWaker::new(std::ptr::null(), &VTABLE)) };
    let mut cx = Context::from_waker(&waker);
    let mut pinned = Box::pin(fut);
    match Pin::as_mut(&mut pinned).poll(&mut cx) {
        Poll::Ready(val) => val,
        Poll::Pending => panic!("expected immediate ready future"),
    }
}

fn main() {
    let svc = service_fn(handle_request);

    let get_req = Request::builder()
        .method(Method::GET)
        .uri("http://localhost/health")
        .version(Version::HTTP_11)
        .body(String::new())
        .expect("valid GET request");

    let get_resp = poll_ready_future(svc.call(get_req)).expect("infallible service");
    assert_eq!(get_resp.status(), StatusCode::OK);
    assert_eq!(get_resp.version(), Version::HTTP_11);
    assert_eq!(
        get_resp.headers().get(CONTENT_TYPE).and_then(|v| v.to_str().ok()),
        Some("text/plain; charset=utf-8")
    );
    assert_eq!(get_resp.into_body(), "ok");

    let post_req = Request::builder()
        .method(Method::POST)
        .uri("http://localhost/echo")
        .body("payload".to_string())
        .expect("valid POST request");
    assert!(!post_req.body().is_end_stream() || post_req.body() == "payload");

    let post_resp = poll_ready_future(svc.call(post_req)).expect("infallible service");
    assert_eq!(post_resp.status(), StatusCode::CREATED);
    assert_eq!(post_resp.into_body(), "echo:payload");

    let missing_req = Request::builder()
        .method(Method::DELETE)
        .uri("http://localhost/missing")
        .body(String::new())
        .expect("valid DELETE request");

    let missing_resp = poll_ready_future(svc.call(missing_req)).expect("infallible service");
    assert_eq!(missing_resp.status(), StatusCode::NOT_FOUND);
    assert_eq!(missing_resp.into_body(), "not found");

    let _frame = Frame::data("chunk");
    println!("CONTRACT_OK");
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn contract_hyper_service_and_types() {
        main();
    }
}

오리진 시더

익명