CodeSampleX

Beispiel

hyper 1.11.0

Verifiziertes Beispiel für cargo hyper 1.11.0. Der Vertrag lief auf rust 1 · linux alpine/x64 · docker und bestand: Request and Response builders construct…

sha256:77d3a4a6f51cad98593fa00f1af71b08bd81e5025524b05b2ec06cd430c3ea53

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux · alpine · musl x64 cargo

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify pkg:cargo/hyper@1.11.0
Pakete
Erstellt
2026-09-18T08:27:11Z

Contract

  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

Dateien

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.rs
  • test/contract.rs

Quellartefakt herunterladen (tar.gz)

Quelltext

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.");
}

Ursprungs-Seeder

anonym