Skip to content

fix(client)!: route manifests by namespace, cut ranges answered whole, and check URI objects - #21

Merged
thiras merged 2 commits into
mainfrom
fix/review-findings
Nov 1, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/review-findings

Conversation

@thiras

@thiras thiras commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Fixes the findings of a repository review of src/, and the follow-ups of a review of the fix. Every gateway behaviour is checked against decdn's crates/cli/src/commands/gateway.rs.

Changes

  • Manifests route by namespace. A manifest read carries the URI's ?ns= hint (the gateway pulls manifests with it), cached by hash and hint. A site's own entries take its host's namespace.
  • Content type of entries fetched by hash. An HTML or CSS entry fetched by its hash, unrewritten, reports the type its site serves (text/html; charset=utf-8), not the bare blob's application/octet-stream.
  • Directory paths. Off loopback, get, head and resolve read <dir> as <dir>/index.html, as a site redirects it (entry() / head_site). Before, verification turned that redirect into NOT_FOUND.
  • Ranges answered whole. A range answered 200 (a page a site rewrites, a proxy that drops Range) has the window cut from the body (slice in src/verify.ts). A window past the end fails with RANGE_NOT_SATISFIABLE, as on a 206. A range is still never verified.
  • Tokenless loopback. Content calls on a loopback client without the token fail with CONFIG before any request, instead of HASH_MISMATCH on a site-rewritten redirect.
  • Manifest reads that stall. A caller that aborts drops the shared read from the cache, so the next caller starts afresh. The last waiter to leave aborts the request. An already-aborted signal sends nothing.
  • Content-Encoding. Content-Length is neither a lower bound nor contentLength for an encoded body.
  • URI objects. DecdnUri objects are checked and normalised as their strings parse (an uppercase hash works; a bad one is BAD_URI).
  • Cleanup. One sendOk (http.ts) and one concat (bytes.ts) replace the copies; dead verified logic is gone.

Fake gateway: it gains a namespaced map (content found only under its ?ns=) and a site directory redirect on GET and HEAD. It also resolves relative Locations, keeping the method.

Breaking

DecdnResponse.contentRange.length and .size are optional. A window cut from a body of unknown length (a rewritten page streams with none) holds its offset alone.

Tests

  • pnpm lint, pnpm test:coverage (275 tests), pnpm build, scripts/check-package.sh: pass.
  • scripts/decdn-contract.sh --tag v0.3.0 (the floor and latest published release): public and loopback contracts pass. This includes the new contract tests: a namespaced manifest and entry, the page's content type, and a window cut from a page answered whole.
  • pnpm test:browser: not run.

Not here

🤖 Generated with Claude Code

…, and check URI objects

- Manifest reads carry the URI's `?ns=` hint, cached by hash and hint; a
  site's own entries take its host's namespace.
- An HTML or CSS entry fetched by its hash reports the type its site serves.
- Off loopback, `get`, `head` and `resolve` read a directory's path as its
  `index.html`, as a site redirects it.
- A range answered with the whole body (200) has the window cut from it;
  one past the end fails with RANGE_NOT_SATISFIABLE.
- A loopback client without the token refuses content calls with CONFIG.
- A manifest read a caller abandons leaves the cache, the last waiter to
  leave aborts it, and an already-aborted signal sends nothing.
- Content-Length is no bound, and no `contentLength`, for an encoded body.
- DecdnUri objects are checked and normalised as their strings parse.
- One `sendOk` and one `concat` replace the copies.

BREAKING CHANGE: `DecdnResponse.contentRange.length` and `.size` are
optional: a window cut from a body of unknown length holds its offset alone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 1, 2026 11:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved client bugs cause namespace-dependent lookups to fail, allow malformed hashes to alter URI fields, and report negative lengths for empty ranged responses.

3 open issues
What changed in this PR

This PR improves @decdn/client gateway compatibility, covering namespace-aware routing, range handling, and URI-object validation. It also makes contentRange.length and .size optional for windows cut from bodies of unknown length.

Changes:

  • Adds namespace-aware manifest caching, abort handling, directory lookup, and entry content types.
  • Slices range requests answered with whole bodies, handles encoded lengths, and rejects tokenless loopback content calls.
  • Consolidates shared helpers and expands unit tests, gateway contract tests, and documentation.
File Description
test/​unit/​verify.test.ts Tests stream slicing, boundaries, cancellation, and errors.
test/​unit/​client.test.ts Adds regression coverage for client behavior changes.
test/​fake-gateway.ts Models namespace-restricted content and directory redirects.
test/​contract/​public.test.ts Adds namespace, content-type, and whole-response range checks.
src/​verify.ts Adds stream slicing and range-boundary errors.
src/​pointer.ts Uses shared byte and HTTP helpers.
src/​loopback.ts Uses the shared successful-response helper.
src/​http.ts Adds sendOk for centralized status checking.
src/​client.ts Updates routing, caching, validation, and response handling.
src/​bytes.ts Adds a shared byte-concatenation helper.
README.md Documents namespace hints, range behavior, and token requirements.

Review effort: Balanced

Comment thread src/client.ts Resolved
Comment thread src/client.ts Resolved
Comment thread src/client.ts Resolved
…r its namespace everywhere, and clamp an empty window

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit 8aeeb19 into main Nov 1, 2026
16 checks passed
@thiras
thiras deleted the fix/review-findings branch November 1, 2026 11:41
alpergundogdu added a commit that referenced this pull request Nov 11, 2026
The public gateway adds `Content-Encoding` to
`Access-Control-Expose-Headers` (decdn/decdn#2817, gateway change in
decdn/decdn#2870). A page on another origin then sees that a proxy in
front encoded the body, so the client skips `Content-Length` as a lower
bound and as `contentLength` (the logic from #21).

## Changes

- `test/fake-gateway.ts`: `EXPOSED` lists `Content-Encoding` after
`Content-Length`, as the gateway does.
- `test/contract/public.test.ts`: a blob read from another origin finds
`content-encoding` and `content-length` in
`access-control-expose-headers`.
- `test/contract/fixture.ts`: `shippedAfter(version)` says whether the
gateway under test carries behaviour decdn shipped after that release.
`scripts/decdn-contract.sh --tag` sets `DECDN_CONTRACT_RELEASE`; the
fake and `--ref` runs (including decdn's own contract run) carry
everything.
- The new test is declared inside `if (shippedAfter("0.3.1"))`. It is
left out, not skipped, because decdn's harness fails a run where any
collected test is skipped. CONTRIBUTING.md describes the pattern.

## Order

This PR merges first. decdn/decdn#2870 pins `.github/sdk-typescript.sha`
to this branch's head.

## Gateway floor

`decdn.gatewayFloor` stays at `0.3.0`. The SDK code does not change, and
the release-gateway runs against v0.3.0 and v0.3.1 do not collect the
new test.

## Tests

- `pnpm lint`, `pnpm build`, `shellcheck scripts/decdn-contract.sh`:
pass.
- `vitest run test/contract test/unit`: 155 passed.
- Public contract against the fake with `DECDN_CONTRACT_RELEASE` set to
0.3.0 or 0.3.1: 16 tests, none skipped. Set to 0.3.2: 17.
- `test/scripts/*` fail locally on macOS (BSD `tar --mtime`, changelog
tool), unrelated to this change.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants