Repository navigation
feat(client): parse and print decdn: URIs - #2455
Conversation
`decdn_client::uri::DecdnUri` names a blob (`decdn:<hash>`), a whole bundle (`decdn:<hash>/`) or one bundle entry (`decdn:<hash>/a/b.txt`), with an optional `?ns=<id>` namespace hint. Entry paths are percent- encoded per RFC 3986 pchar and held to the manifest path rules; the canonical `Display` form round-trips. This is the parser half of #2449; `decdn get` builds on it separately. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
The change is an isolated, pure-logic parser module with exhaustive tests and correct edge-case handling that follows established workspace conventions, and no defects were found.
0 open findings
What changed in this PR
This PR adds the parser half of #2449: a new decdn_client::uri module that parses and canonically prints decdn:<hash>[/<path>][?ns=<id>] URIs, which name a blob, a whole bundle, or a single bundle entry with an optional namespace routing hint. The URI is client-side syntax only — it resolves to the BLAKE3 hash and namespace_id the wire already carries — so no node or protocol changes are involved. It is self-contained (no CLI wiring yet); the decdn get command and decdn gateway consumer land in stacked PRs.
Changes:
- Introduce
DecdnUriwithFromStr(hand-rolled parsing, no new dependency) and a canonicalDisplaythat round-trips, plusUriTarget, a typedUriError, and aSCHEMEconstant. - Validate hashes (64 bare hex, no
b3:/0x), entry paths (per-segmentpcharpercent-decoding; reject./.., empty, encoded/, NUL, non-pchar, bad escapes, non-UTF-8), andns(decimal, non-zero, single). - Export the module from
lib.rsand regenerate thepublic_apisnapshot.
| File | Description |
|---|---|
crates/client/src/uri.rs |
New decdn: URI module: DecdnUri/UriTarget/UriError, FromStr, canonical Display, and private hash/path/query validators. |
crates/client/src/uri/tests.rs |
11 unit tests covering every target kind, namespace hint, round-trip, uppercase hex, percent-encoding, and all rejection paths. |
crates/client/src/lib.rs |
Exports pub mod uri; with a doc-comment-placement note mirroring the existing sink pattern. |
crates/client/tests/snapshots/public_api__public_api.snap |
Records the new uri public surface in the API snapshot. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Summary
The parser half of #2449:
decdn_client::uri::DecdnUrinames a blob, a whole bundle, or one bundle entry, with an optional namespace hint.targetdecdn:<hash>UriTarget::Blobdecdn:<hash>/UriTarget::Bundledecdn:<hash>/a/b.txtUriTarget::BundleEntry("a/b.txt")?ns=42namespace: Some(42)FromStrparses;Displaywrites the canonical form (lowercase hex, entry segments percent-encoded as RFC 3986pchar), which round-trips.b3:/0xprefixes, wrong length or non-hex, a//authority,ns=0or non-decimalns, unknown or duplicate query keys, and entry paths with./.., empty segments, encoded/, NUL, raw non-pcharcharacters, bad escapes, or non-UTF-8 once decoded.UriError(hand-rolled, no new dependency).public_apisnapshot updated: the diff is the newurimodule only.decdn get(replacingfetchandbundle pull) stays its own piece of #2449. The first user of this parser isdecdn gateway(#2456), which is stacked on this branch: merge this first.Checks
cargo nextest run -p decdn-client uri::: 11 testscargo clippy -p decdn-client --all-targets --all-features -D warningscargo doc -p decdn-clientwith-D warningsPart of #2449.
🤖 Generated with Claude Code