Exemplo
http 1.4.0: http::HeaderMap
Amostra verificada para cargo http 1.4.0: http::HeaderMap. O contrato rodou em rust 1 · linux alpine/x64 · docker e passou: HeaderMap::insert accepts…
sha256:5665f08ad4a53f49640ca3ee8387f1fd2574a80b14b9ae64d0306e1504def54c
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
linux · alpine · musl x64 cargo
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| 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-16 |
Caso
HOW- Objetivo
- verify http::HeaderMap in pkg:cargo/http@1.4.0
- Pacotes
- Símbolos
-
- http::HeaderMap
- Criado
- 2026-11-16T23:15:31Z
Contrato
- HeaderMap::insert accepts HeaderName constants, lowercase &'static str keys, and runtime HeaderName::from_bytes keys while AsHeaderName lookups match case-insensitively on dynamic &str
- HeaderMap::append adds multiple values under one key, returning false on first insert and true on subsequent appends, while keys_len counts distinct keys and len counts total values
- HeaderMap::get returns the first value, HeaderMap::get_all iterates all values in insertion order, and subsequent HeaderMap::insert replaces all values for that key returning the first previous value
- HeaderMap::entry takes IntoHeaderName directly and returns Entry<'_, T> supporting VacantEntry::insert and OccupiedEntry::append
- FromIterator<(HeaderName, T)> appends repeated keys and IntoIterator yields (Some(HeaderName), T) for the first value of each key followed by (None, T) for additional values
- Generic HeaderMap<T> stores arbitrary value types keyed by HTTP header names
Arquivos
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/lib.rs
- test/contract.rs
Código-fonte
# 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.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a"
dependencies = [
"bytes",
"itoa",
]
[[package]]
name = "itoa"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
[[package]]
name = "sample-http-headermap"
version = "1.0.0"
dependencies = [
"http",
]
[package]
name = "sample-http-headermap"
version = "1.0.0"
edition = "2021"
publish = false
[dependencies]
http = "=1.4.0"
[[bin]]
name = "contract"
path = "test/contract.rs"
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 http::HeaderMap in pkg:cargo/http@1.4.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/http@1.4.0
Demonstrate these symbols/APIs:
- http::HeaderMap
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.
{"case":{"caseId":"case:sha256:a368b86fb8a11a99b323447c39b69e45830163608eae667cdf524d670d17e415","contract":["HeaderMap::insert accepts HeaderName constants, lowercase \u0026'static str keys, and runtime HeaderName::from_bytes keys while AsHeaderName lookups match case-insensitively on dynamic \u0026str","HeaderMap::append adds multiple values under one key, returning false on first insert and true on subsequent appends, while keys_len counts distinct keys and len counts total values","HeaderMap::get returns the first value, HeaderMap::get_all iterates all values in insertion order, and subsequent HeaderMap::insert replaces all values for that key returning the first previous value","HeaderMap::entry takes IntoHeaderName directly and returns Entry\u003c'_, T\u003e supporting VacantEntry::insert and OccupiedEntry::append","FromIterator\u003c(HeaderName, T)\u003e appends repeated keys and IntoIterator yields (Some(HeaderName), T) for the first value of each key followed by (None, T) for additional values","Generic HeaderMap\u003cT\u003e stores arbitrary value types keyed by HTTP header names"],"goal":"verify http::HeaderMap in pkg:cargo/http@1.4.0","kind":"HOW","packages":["pkg:cargo/http@1.4.0"],"schemaVersion":1,"symbols":["http::HeaderMap"]},"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/http@1.4.0"],"schemaVersion":1,"subject":"pkg:cargo/http@1.4.0","symbols":["http::HeaderMap"],"verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify http::HeaderMap in pkg:cargo/http@1.4.0",
"kind": "HOW",
"packages": [
"pkg:cargo/http@1.4.0"
],
"symbols": [
"http::HeaderMap"
]
}
//! Clean-room verification sample for `http::HeaderMap` in `http@1.4.0`.
pub use http::HeaderMap;
use http::header::{HeaderName, HeaderValue, InvalidHeaderName, InvalidHeaderValue};
/// Inserts a dynamically owned header name and value into a `HeaderMap`.
///
/// Runtime `&str` / `String` does not implement `IntoHeaderName` (`E0277`), so dynamic
/// names must be parsed into `HeaderName` before calling `HeaderMap::insert`.
pub fn insert_dynamic_header(
map: &mut HeaderMap,
name: &str,
value: &str,
) -> Result<Option<HeaderValue>, DynamicHeaderError> {
let parsed_name = HeaderName::from_bytes(name.as_bytes()).map_err(DynamicHeaderError::Name)?;
let parsed_value = HeaderValue::from_str(value).map_err(DynamicHeaderError::Value)?;
Ok(map.insert(parsed_name, parsed_value))
}
#[derive(Debug)]
pub enum DynamicHeaderError {
Name(InvalidHeaderName),
Value(InvalidHeaderValue),
}
use http::header::{self, Entry, HeaderName, HeaderValue};
use sample_http_headermap::{insert_dynamic_header, HeaderMap};
fn main() {
// 1. Insertion with HeaderName constants, lowercase &'static str, and parsed runtime HeaderName
let mut map = HeaderMap::with_capacity(8);
assert!(map.is_empty());
assert_eq!(
map.insert(header::CONTENT_TYPE, HeaderValue::from_static("application/json")),
None
);
assert_eq!(
map.insert("x-request-id", HeaderValue::from_static("req-001")),
None
);
let dynamic_name = String::from("X-Correlation-Id");
let prev_dyn = insert_dynamic_header(&mut map, &dynamic_name, "corr-42").expect("valid header");
assert!(prev_dyn.is_none());
// AsHeaderName lookups accept runtime &str and match case-insensitively
let mixed_lookup = String::from("X-CORRELATION-ID");
assert!(map.contains_key(mixed_lookup.as_str()));
assert_eq!(map.get(mixed_lookup.as_str()).unwrap(), "corr-42");
assert_eq!(map.get("CONTENT-TYPE").unwrap(), "application/json");
assert_eq!(map.get("X-Request-Id").unwrap(), "req-001");
// Invalid header name bytes fail validation cleanly
assert!(insert_dynamic_header(&mut map, "bad header name", "val").is_err());
// 2. Multi-value append vs keys_len() and len()
assert!(!map.append(header::CACHE_CONTROL, HeaderValue::from_static("no-cache")));
assert!(map.append(header::CACHE_CONTROL, HeaderValue::from_static("no-store")));
assert!(map.append("cache-control", HeaderValue::from_static("must-revalidate")));
assert_eq!(map.keys_len(), 4);
assert_eq!(map.len(), 6);
// 3. get() vs get_all() and replacement via insert()
assert_eq!(map.get(header::CACHE_CONTROL).unwrap(), "no-cache");
let all_cache_control: Vec<&str> = map
.get_all(header::CACHE_CONTROL)
.iter()
.map(|v| v.to_str().unwrap())
.collect();
assert_eq!(
all_cache_control,
vec!["no-cache", "no-store", "must-revalidate"]
);
let replaced = map.insert(header::CACHE_CONTROL, HeaderValue::from_static("max-age=60"));
assert_eq!(replaced.unwrap(), "no-cache");
assert_eq!(map.keys_len(), 4);
assert_eq!(map.len(), 4);
assert_eq!(map.get_all(header::CACHE_CONTROL).iter().count(), 1);
assert_eq!(map.get(header::CACHE_CONTROL).unwrap(), "max-age=60");
// 4. entry() takes IntoHeaderName directly and returns Entry<'_, T>
match map.entry("x-retry-count") {
Entry::Occupied(_) => panic!("expected vacant entry"),
Entry::Vacant(vacant) => {
vacant.insert(HeaderValue::from_static("1"));
}
}
if let Entry::Occupied(mut occupied) = map.entry("x-retry-count") {
occupied.append(HeaderValue::from_static("2"));
let retry_vals: Vec<&str> = occupied.iter().map(|v| v.to_str().unwrap()).collect();
assert_eq!(retry_vals, vec!["1", "2"]);
} else {
panic!("expected occupied entry");
}
let removed = map.remove("X-RETRY-COUNT");
assert_eq!(removed.unwrap(), "1");
assert!(!map.contains_key("x-retry-count"));
// 5. FromIterator appends duplicate keys; IntoIterator groups continuation values under None
let collected: HeaderMap<HeaderValue> = vec![
(header::ACCEPT, HeaderValue::from_static("text/html")),
(header::ACCEPT, HeaderValue::from_static("application/json")),
(HeaderName::from_static("x-mode"), HeaderValue::from_static("strict")),
]
.into_iter()
.collect();
assert_eq!(collected.keys_len(), 2);
assert_eq!(collected.len(), 3);
let items: Vec<(Option<HeaderName>, HeaderValue)> = collected.into_iter().collect();
assert_eq!(items.len(), 3);
assert_eq!(items[0].0.as_ref().unwrap(), header::ACCEPT);
assert_eq!(items[0].1, "text/html");
assert!(items[1].0.is_none());
assert_eq!(items[1].1, "application/json");
assert_eq!(items[2].0.as_ref().unwrap(), "x-mode");
assert_eq!(items[2].1, "strict");
// 6. Generic HeaderMap<T> stores typed non-HeaderValue payloads
let mut typed_limits: HeaderMap<u32> = HeaderMap::default();
assert_eq!(typed_limits.insert("x-rate-limit", 120), None);
assert_eq!(typed_limits.get("X-RATE-LIMIT"), Some(&120));
println!("All http::HeaderMap contract assertions passed.");
}
Seeder de origem
anônimo