CodeSampleX

샘플

hyper 1.11.0

검증된 샘플 — cargo hyper 1.11.0. rust 1 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: Request and Response builders construct typed HTTP requests and…

sha256:77d3a4a6f51cad98593fa00f1af71b08bd81e5025524b05b2ec06cd430c3ea53

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

실행 증거

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

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux · alpine · musl x64 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-09-19

케이스

HOW
목표
verify pkg:cargo/hyper@1.11.0
패키지
생성일
2026-09-18T08:27:11Z

컨트랙트

  1. Request and Response builders construct typed HTTP requests and responses with status, version, headers, and body
  2. Frame produces data and trailers frames, and SizeHint tracks streaming body dimensions
  3. service_fn wraps closures into callable Service implementations
  4. ReadBuf manages byte slice initialization and cursor advancement for runtime I/O

파일

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.rs
  • test/contract.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.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d22053281f852e11534f5198498373cbb59295120a20771d90f7ed1897490a72"
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 = "1.0.0"
dependencies = [
 "hyper",
]

[[package]]
name = "tokio"
version = "1.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed"
dependencies = [
 "pin-project-lite",
]
Cargo.toml
[package]
name = "sample-hyper"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
hyper = "=1.11.0"

[[bin]]
name = "contract"
path = "test/contract.rs"
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.11.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/hyper@1.11.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:971e709d5249bd9b1f3f2f532669e736c8fcd90f834d9d6e13c88b68f88e8992","contract":["Request and Response builders construct typed HTTP requests and responses with status, version, headers, and body","Frame produces data and trailers frames, and SizeHint tracks streaming body dimensions","service_fn wraps closures into callable Service implementations","ReadBuf manages byte slice initialization and cursor advancement for runtime I/O"],"goal":"verify pkg:cargo/hyper@1.11.0","kind":"HOW","packages":["pkg:cargo/hyper@1.11.0"],"schemaVersion":1},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"cargo","libc":"musl","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/hyper@1.11.0"],"schemaVersion":1,"subject":"pkg:cargo/hyper@1.11.0","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/hyper@1.11.0",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/hyper@1.11.0"
  ]
}
src/lib.rs
//! Clean-room verification sample for hyper.

pub use hyper::*;
test/contract.rs
use std::convert::Infallible;
use hyper::body::{Bytes, Frame, SizeHint};
use hyper::header::{HeaderMap, HeaderValue, CONTENT_TYPE, USER_AGENT};
use hyper::rt::ReadBuf;
use hyper::service::{service_fn, Service};
use hyper::{Method, Request, Response, StatusCode, Uri, Version};

fn main() {
    // 1. Request and Response builders construct typed HTTP requests and responses with status, version, headers, and body
    let req = Request::builder()
        .method(Method::POST)
        .uri("https://example.com/api/test")
        .version(Version::HTTP_11)
        .header(CONTENT_TYPE, "application/json")
        .header(USER_AGENT, "hyper-contract-test")
        .body(String::from("{\"key\":\"value\"}"))
        .expect("failed to build request");

    assert_eq!(req.method(), Method::POST);
    assert_eq!(req.uri().path(), "/api/test");
    assert_eq!(req.version(), Version::HTTP_11);
    assert_eq!(
        req.headers().get(CONTENT_TYPE),
        Some(&HeaderValue::from_static("application/json"))
    );
    assert_eq!(req.body(), "{\"key\":\"value\"}");

    let uri: Uri = "https://example.com:8080/path?query=1#frag".parse().unwrap();
    assert_eq!(uri.scheme_str(), Some("https"));
    assert_eq!(uri.authority().map(|a| a.as_str()), Some("example.com:8080"));
    assert_eq!(uri.path(), "/path");

    let res = Response::builder()
        .status(StatusCode::OK)
        .version(Version::HTTP_11)
        .header("X-Custom-Header", "contract-passed")
        .body(String::from("OK"))
        .expect("failed to build response");

    assert_eq!(res.status(), StatusCode::OK);
    assert!(res.status().is_success());
    assert_eq!(res.version(), Version::HTTP_11);
    assert_eq!(
        res.headers().get("X-Custom-Header"),
        Some(&HeaderValue::from_static("contract-passed"))
    );
    assert_eq!(res.body(), "OK");

    // 2. Frame produces data and trailers frames, and SizeHint tracks streaming body dimensions
    let data_frame = Frame::data(Bytes::from_static(b"stream-data-chunk"));
    assert!(data_frame.is_data());
    assert!(!data_frame.is_trailers());
    assert_eq!(data_frame.data_ref(), Some(&Bytes::from_static(b"stream-data-chunk")));

    let mut trailers = HeaderMap::new();
    trailers.insert("x-checksum", HeaderValue::from_static("abc123xyz"));
    let trailer_frame = Frame::<Bytes>::trailers(trailers);
    assert!(trailer_frame.is_trailers());
    assert!(!trailer_frame.is_data());
    assert!(trailer_frame.trailers_ref().unwrap().contains_key("x-checksum"));

    let exact_hint = SizeHint::with_exact(1024);
    assert_eq!(exact_hint.exact(), Some(1024));
    assert_eq!(exact_hint.lower(), 1024);
    assert_eq!(exact_hint.upper(), Some(1024));

    let default_hint = SizeHint::default();
    assert_eq!(default_hint.lower(), 0);
    assert_eq!(default_hint.upper(), None);

    // 3. service_fn wraps synchronous or async closures into Service implementations
    let echo_service = service_fn(|req: Request<String>| {
        let body = req.into_body();
        let res = Response::builder()
            .status(StatusCode::CREATED)
            .body(format!("Echo: {}", body))
            .unwrap();
        std::future::ready(Ok::<Response<String>, Infallible>(res))
    });

    let service_req = Request::builder()
        .method(Method::PUT)
        .uri("/echo")
        .body(String::from("ping"))
        .unwrap();

    let fut = echo_service.call(service_req);
    let mut pinned_fut = Box::pin(fut);
    let waker = std::task::Waker::noop();
    let mut cx = std::task::Context::from_waker(&waker);
    match std::future::Future::poll(pinned_fut.as_mut(), &mut cx) {
        std::task::Poll::Ready(Ok(resp)) => {
            assert_eq!(resp.status(), StatusCode::CREATED);
            assert_eq!(resp.body(), "Echo: ping");
        }
        _ => panic!("Expected immediate readiness for std::future::ready"),
    }

    // 4. ReadBuf manages byte slice initialization and cursor advancement for runtime I/O
    let mut buffer = [0u8; 64];
    let mut read_buf = ReadBuf::new(&mut buffer);
    assert_eq!(read_buf.filled().len(), 0);

    unsafe {
        let mut cursor = read_buf.unfilled();
        let bytes = b"hyper-contract-runtime";
        for (i, &b) in bytes.iter().enumerate() {
            cursor.as_mut()[i].write(b);
        }
        cursor.advance(bytes.len());
    }
    assert_eq!(read_buf.filled(), b"hyper-contract-runtime");

    println!("All hyper 1.11.0 contract assertions passed successfully.");
}

오리진 시더

익명