Exemple
hyper-rustls 0.27.9: hyper_rustls::HttpsConnectorBuilder
Échantillon vérifié pour cargo hyper-rustls 0.27.9: hyper_rustls::HttpsConnectorBuilder. Le contrat s'est exécuté sur rust 1 · linux alpine/x64 · docker et a…
sha256:7fd384179616a834c2d51cdce7b2f8fc92dbe8f77769d49d2e747be7070affbb
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
linux · alpine · musl x64 cargo
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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-23 |
Cas
HOW- Objectif
- verify hyper_rustls::HttpsConnectorBuilder in pkg:cargo/hyper-rustls@0.27.9
- Paquets
- Symboles
-
- hyper_rustls::HttpsConnectorBuilder
- Créé
- 2026-11-23T18:29:44Z
Contrat
- HttpsConnectorBuilder::new().with_provider_and_webpki_roots() builds an https_only connector without a global default CryptoProvider
- https_only() rejects http://, unsupported schemes, and missing-scheme URIs offline before dialing
- HttpsConnectorBuilder::default().with_webpki_roots().https_or_http().enable_http1().build() connects to an offline loopback HTTP listener and returns MaybeHttpsStream::Http
- with_tls_config() panics with 'ALPN protocols should not be pre-defined' when ClientConfig.alpn_protocols is non-empty
- enable_http1(), enable_http2(), enable_http1().enable_http2(), and enable_all_versions() build HttpsConnector instances cleanly
- with_server_name_resolver() and wrap_connector() short-circuit on resolver errors and delegate to the wrapped inner Service<Uri> when resolution succeeds
Fichiers
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/lib.rs
- test/contract.rs
Code source
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "atomic-waker"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
[[package]]
name = "bytes"
version = "1.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "776dfebd015e2d8732c684a2c71003674ccb49457b539b9e82151ba38e96dd7c"
[[package]]
name = "cc"
version = "1.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02f0e023adb368345ce0ca6cdfc0f24a06554468d0e8503e14a0841de79bfa69"
dependencies = [
"find-msvc-tools",
"shlex",
]
[[package]]
name = "cfg-if"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
[[package]]
name = "equivalent"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"
[[package]]
name = "find-msvc-tools"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "futures-channel"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4"
dependencies = [
"futures-core",
]
[[package]]
name = "futures-core"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
[[package]]
name = "futures-sink"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d"
[[package]]
name = "futures-task"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd"
[[package]]
name = "futures-util"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
dependencies = [
"futures-core",
"futures-task",
"pin-project-lite",
]
[[package]]
name = "getrandom"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "h2"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d29020232d6aa3fb1daca64c1127cf662cf97f254ae16c18c05b8ab635fc118"
dependencies = [
"atomic-waker",
"bytes",
"fnv",
"futures-core",
"futures-sink",
"http",
"indexmap",
"slab",
"tokio",
"tokio-util",
"tracing",
]
[[package]]
name = "hashbrown"
version = "0.17.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "735eaa21a6a5ffb2e84362faaeb90c05ba8e19797ca30428478cb6ea3a4921bc"
[[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 = "httparse"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"
[[package]]
name = "hyper"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c3e324da4c95177d6291d4c8730197c0d1822f8a9766814a4a44fa5ab797c9c"
dependencies = [
"atomic-waker",
"bytes",
"futures-channel",
"futures-core",
"h2",
"http",
"http-body",
"httparse",
"itoa",
"pin-project-lite",
"smallvec",
"tokio",
"want",
]
[[package]]
name = "hyper-rustls"
version = "0.27.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f"
dependencies = [
"http",
"hyper",
"hyper-util",
"rustls",
"tokio",
"tokio-rustls",
"tower-service",
"webpki-roots",
]
[[package]]
name = "hyper-util"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddc03d96684f9226b8a787cdb71488417b53ab5ea8fdb1dac946cb9431cc8bff"
dependencies = [
"bytes",
"futures-channel",
"futures-util",
"http",
"http-body",
"httparse",
"hyper",
"libc",
"pin-project-lite",
"socket2",
"tokio",
"tower-service",
"tracing",
]
[[package]]
name = "indexmap"
version = "2.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "itoa"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
[[package]]
name = "libc"
version = "0.2.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
[[package]]
name = "mio"
version = "1.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20521a903f02b0a573cd6840e9d0a5a0cc043d361fe924092cd70f8556cc9c4a"
dependencies = [
"libc",
"wasi",
"windows-sys 0.61.2",
]
[[package]]
name = "once_cell"
version = "1.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
[[package]]
name = "pin-project-lite"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c938015719552d665fd0553b90d96cd7ff58e83e4c061ca99e6bb78865a72752"
[[package]]
name = "ring"
version = "0.17.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
dependencies = [
"cc",
"cfg-if",
"getrandom",
"libc",
"untrusted",
"windows-sys 0.52.0",
]
[[package]]
name = "rustls"
version = "0.23.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf"
dependencies = [
"once_cell",
"ring",
"rustls-pki-types",
"rustls-webpki",
"subtle",
"zeroize",
]
[[package]]
name = "rustls-pki-types"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "102f35f7de7b06d8c61f1cff6592f5253e0dea431c74867aad5dfd70f44663fb"
dependencies = [
"zeroize",
]
[[package]]
name = "rustls-webpki"
version = "0.103.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3a0760a887c14823fca5a1c970b01d47c328c696c0c64829d1df50e8f853fd5"
dependencies = [
"ring",
"rustls-pki-types",
"untrusted",
]
[[package]]
name = "sample-hyper-rustls-builder"
version = "1.0.0"
dependencies = [
"http",
"hyper",
"hyper-rustls",
"hyper-util",
"rustls",
"tokio",
"tower-service",
]
[[package]]
name = "shlex"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
[[package]]
name = "slab"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
[[package]]
name = "smallvec"
version = "1.16.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3244542535d5de959d90ec55d1b5ff0fd2bb7b1310223907d5f11932847f7b59"
[[package]]
name = "socket2"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4"
dependencies = [
"libc",
"windows-sys 0.61.2",
]
[[package]]
name = "subtle"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "tokio"
version = "1.54.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b52fd3255258d26fac7264ab5a76b53c13367136dc011d3d6ad4f8ed070396a3"
dependencies = [
"bytes",
"libc",
"mio",
"pin-project-lite",
"socket2",
"windows-sys 0.61.2",
]
[[package]]
name = "tokio-rustls"
version = "0.26.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9cc2678c2cdd569ef8215e2afd7954ada2ae20b4fdd2c5fe6139a3b02d105db"
dependencies = [
"rustls",
"tokio",
]
[[package]]
name = "tokio-util"
version = "0.7.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e464cf451ba96ebfc6f9b6542f17ee8b8956e33f1e40d9690624e59d7a7f8a4b"
dependencies = [
"bytes",
"futures-core",
"futures-sink",
"libc",
"pin-project-lite",
"tokio",
]
[[package]]
name = "tower-service"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
[[package]]
name = "tracing"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
dependencies = [
"pin-project-lite",
"tracing-core",
]
[[package]]
name = "tracing-core"
version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
dependencies = [
"once_cell",
]
[[package]]
name = "try-lock"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]]
name = "untrusted"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
[[package]]
name = "want"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec4cdd0dd910afe868b7ef477227d8d538b46b3075031afee8a9f2acb0a2ed0b"
dependencies = [
"try-lock",
]
[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
[[package]]
name = "webpki-roots"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7265c9301c16a8711c992c2d8da90ee77ef54b1ed51482d6dfeb00dc756b1297"
dependencies = [
"rustls-pki-types",
]
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "zeroize"
version = "1.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85ccff8a4805aba1eaa4cd4afcd49f7557dd2cf5fd79ffc37f8959466effc5aa"
[package]
name = "sample-hyper-rustls-builder"
version = "1.0.0"
edition = "2021"
publish = false
[dependencies]
http = "1"
hyper = { version = "1", default-features = false }
hyper-rustls = { version = "=0.27.9", default-features = false, features = ["http1", "http2", "tls12", "webpki-roots", "ring"] }
hyper-util = { version = "0.1", default-features = false, features = ["client-legacy", "http1", "http2", "tokio"] }
rustls = { version = "0.23", default-features = false, features = ["ring", "tls12"] }
tokio = { version = "1", features = ["rt", "net"] }
tower-service = "0.3"
[[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 hyper_rustls::HttpsConnectorBuilder in pkg:cargo/hyper-rustls@0.27.9
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/hyper-rustls@0.27.9
Demonstrate these symbols/APIs:
- hyper_rustls::HttpsConnectorBuilder
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:f077d4fc138a3971909ae2169f7b670b3532d806d55be031daf47c19ec9cffed","contract":["HttpsConnectorBuilder::new().with_provider_and_webpki_roots() builds an https_only connector without a global default CryptoProvider","https_only() rejects http://, unsupported schemes, and missing-scheme URIs offline before dialing","HttpsConnectorBuilder::default().with_webpki_roots().https_or_http().enable_http1().build() connects to an offline loopback HTTP listener and returns MaybeHttpsStream::Http","with_tls_config() panics with 'ALPN protocols should not be pre-defined' when ClientConfig.alpn_protocols is non-empty","enable_http1(), enable_http2(), enable_http1().enable_http2(), and enable_all_versions() build HttpsConnector instances cleanly","with_server_name_resolver() and wrap_connector() short-circuit on resolver errors and delegate to the wrapped inner Service\u003cUri\u003e when resolution succeeds"],"goal":"verify hyper_rustls::HttpsConnectorBuilder in pkg:cargo/hyper-rustls@0.27.9","kind":"HOW","packages":["pkg:cargo/hyper-rustls@0.27.9"],"schemaVersion":1,"symbols":["hyper_rustls::HttpsConnectorBuilder"]},"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-rustls@0.27.9"],"schemaVersion":1,"subject":"pkg:cargo/hyper-rustls@0.27.9","symbols":["hyper_rustls::HttpsConnectorBuilder"],"verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify hyper_rustls::HttpsConnectorBuilder in pkg:cargo/hyper-rustls@0.27.9",
"kind": "HOW",
"packages": [
"pkg:cargo/hyper-rustls@0.27.9"
],
"symbols": [
"hyper_rustls::HttpsConnectorBuilder"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder, ResolveServerName};
use hyper_util::client::legacy::connect::HttpConnector;
use rustls::crypto::CryptoProvider;
use rustls::ClientConfig;
pub fn build_with_explicit_provider_https_only(
provider: CryptoProvider,
) -> Result<HttpsConnector<HttpConnector>, rustls::Error> {
Ok(HttpsConnectorBuilder::new()
.with_provider_and_webpki_roots(provider)?
.https_only()
.enable_http1()
.build())
}
pub fn build_with_default_provider_https_or_http() -> HttpsConnector<HttpConnector> {
HttpsConnectorBuilder::default()
.with_webpki_roots()
.https_or_http()
.enable_http1()
.build()
}
pub fn build_http2_only(config: ClientConfig) -> HttpsConnector<HttpConnector> {
HttpsConnectorBuilder::new()
.with_tls_config(config)
.https_only()
.enable_http2()
.build()
}
pub fn build_http1_and_http2(config: ClientConfig) -> HttpsConnector<HttpConnector> {
HttpsConnectorBuilder::new()
.with_tls_config(config)
.https_only()
.enable_http1()
.enable_http2()
.build()
}
pub fn build_all_versions(config: ClientConfig) -> HttpsConnector<HttpConnector> {
HttpsConnectorBuilder::new()
.with_tls_config(config)
.https_only()
.enable_all_versions()
.build()
}
pub fn wrap_https_only_with_resolver<H, R>(
config: ClientConfig,
resolver: R,
inner: H,
) -> HttpsConnector<H>
where
R: ResolveServerName + Send + Sync + 'static,
{
HttpsConnectorBuilder::new()
.with_tls_config(config)
.https_only()
.with_server_name_resolver(resolver)
.enable_http1()
.wrap_connector(inner)
}
use std::future::{poll_fn, Future};
use std::io;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::pin::Pin;
use std::sync::{Arc, Mutex};
use std::task::{Context, Poll};
use http::Uri;
use hyper_rustls::{FixedServerNameResolver, HttpsConnector, HttpsConnectorBuilder, MaybeHttpsStream};
use hyper_util::rt::TokioIo;
use rustls::pki_types::ServerName;
use rustls::{ClientConfig, RootCertStore};
use sample_hyper_rustls_builder::{
build_all_versions, build_http1_and_http2, build_http2_only,
build_with_default_provider_https_or_http, build_with_explicit_provider_https_only,
wrap_https_only_with_resolver,
};
use tokio::net::{TcpListener, TcpStream};
use tower_service::Service;
#[derive(Clone, Default)]
struct RecordingConnector {
seen: Arc<Mutex<Vec<String>>>,
}
impl Service<Uri> for RecordingConnector {
type Response = TokioIo<TcpStream>;
type Error = io::Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, req: Uri) -> Self::Future {
self.seen.lock().unwrap().push(req.to_string());
Box::pin(async { Err(io::Error::other("stub-connector-invoked")) })
}
}
fn empty_tls_config() -> ClientConfig {
ClientConfig::builder()
.with_root_certificates(RootCertStore::empty())
.with_no_client_auth()
}
fn main() {
let rt = tokio::runtime::Builder::new_current_thread()
.enable_io()
.build()
.expect("tokio runtime");
// 1. with_provider_and_webpki_roots works before installing a global default CryptoProvider.
let mut https_only =
build_with_explicit_provider_https_only(rustls::crypto::ring::default_provider())
.expect("explicit provider builder succeeds");
assert!(
format!("{https_only:?}").contains("force_https: true"),
"https_only should set force_https: true"
);
// 2. https_only rejects http, unsupported schemes, and missing schemes offline.
rt.block_on(async {
poll_fn(|cx| https_only.poll_ready(cx))
.await
.expect("poll_ready");
let http_err = https_only
.call(Uri::from_static("http://localhost:80"))
.await
.expect_err("http must be rejected when https_only");
assert_eq!(http_err.to_string(), "unsupported scheme http");
let ftp_err = https_only
.call(Uri::from_static("ftp://example.com"))
.await
.expect_err("ftp must be rejected");
assert_eq!(ftp_err.to_string(), "unsupported scheme ftp");
let missing_err = https_only
.call(Uri::from_static("/no-scheme"))
.await
.expect_err("missing scheme must be rejected");
assert_eq!(missing_err.to_string(), "missing scheme");
});
// Install ring as the default CryptoProvider for shorthand methods that rely on it.
let _ = rustls::crypto::ring::default_provider().install_default();
// 3. with_webpki_roots + https_or_http connects to an offline loopback HTTP listener.
let mut https_or_http = build_with_default_provider_https_or_http();
assert!(
format!("{https_or_http:?}").contains("force_https: false"),
"https_or_http should set force_https: false"
);
rt.block_on(async {
let listener = TcpListener::bind("127.0.0.1:0")
.await
.expect("bind loopback listener");
let addr = listener.local_addr().expect("local addr");
let accept_task = tokio::spawn(async move { listener.accept().await });
poll_fn(|cx| https_or_http.poll_ready(cx))
.await
.expect("poll_ready");
let uri = Uri::builder()
.scheme("http")
.authority(addr.to_string())
.path_and_query("/")
.build()
.expect("valid loopback uri");
let stream = https_or_http
.call(uri)
.await
.expect("https_or_http should allow loopback http");
assert!(
matches!(stream, MaybeHttpsStream::Http(_)),
"expected MaybeHttpsStream::Http for plain HTTP loopback connection"
);
let _ = accept_task.await.expect("accept task").expect("accepted");
});
// 4. with_tls_config rejects pre-populated alpn_protocols with a panic.
let mut preconfigured = empty_tls_config();
preconfigured.alpn_protocols = vec![b"h2".to_vec()];
let panic_payload = catch_unwind(AssertUnwindSafe(move || {
let _ = HttpsConnectorBuilder::new().with_tls_config(preconfigured);
}))
.expect_err("with_tls_config must panic when alpn_protocols is non-empty");
let panic_msg = panic_payload
.downcast_ref::<&str>()
.copied()
.or_else(|| panic_payload.downcast_ref::<String>().map(String::as_str))
.unwrap_or("");
assert!(
panic_msg.contains("ALPN protocols should not be pre-defined"),
"unexpected panic message: {panic_msg}"
);
// 5. HTTP/2, HTTP/1+HTTP/2, all-versions, and HttpsConnector::<HttpConnector>::builder() build cleanly.
let c_h2 = build_http2_only(empty_tls_config());
let c_h1_h2 = build_http1_and_http2(empty_tls_config());
let c_all = build_all_versions(empty_tls_config());
let c_via_connector =
HttpsConnector::<hyper_util::client::legacy::connect::HttpConnector>::builder()
.with_tls_config(empty_tls_config())
.https_only()
.enable_http1()
.build();
for conn in [&c_h2, &c_h1_h2, &c_all, &c_via_connector] {
assert!(format!("{conn:?}").contains("force_https: true"));
}
// 6. with_server_name_resolver + wrap_connector: resolver error short-circuits before dialing.
let stub_fail = RecordingConnector::default();
let seen_fail = stub_fail.seen.clone();
let mut wrapped_fail = wrap_https_only_with_resolver(
empty_tls_config(),
|_uri: &Uri| -> Result<ServerName<'static>, io::Error> {
Err(io::Error::other("custom-resolver-error"))
},
stub_fail,
);
rt.block_on(async {
poll_fn(|cx| wrapped_fail.poll_ready(cx))
.await
.expect("poll_ready");
let err = wrapped_fail
.call(Uri::from_static("https://example.com"))
.await
.expect_err("failing resolver should error");
assert_eq!(err.to_string(), "custom-resolver-error");
assert!(
seen_fail.lock().unwrap().is_empty(),
"wrapped connector must not be called when server name resolution fails"
);
});
// 7. FixedServerNameResolver + wrap_connector invokes the wrapped inner connector.
let stub_ok = RecordingConnector::default();
let seen_ok = stub_ok.seen.clone();
let fixed_name = ServerName::try_from("example.com").expect("valid server name");
let mut wrapped_ok = wrap_https_only_with_resolver(
empty_tls_config(),
FixedServerNameResolver::new(fixed_name),
stub_ok,
);
rt.block_on(async {
poll_fn(|cx| wrapped_ok.poll_ready(cx))
.await
.expect("poll_ready");
let err = wrapped_ok
.call(Uri::from_static("https://localhost:8443/check"))
.await
.expect_err("stub connector returns sentinel error");
assert_eq!(err.to_string(), "stub-connector-invoked");
let recorded = seen_ok.lock().unwrap();
assert_eq!(recorded.as_slice(), &["https://localhost:8443/check"]);
});
println!("ALL_CONTRACT_ASSERTIONS_PASSED");
}
Seeder d'origine
anonyme