Repository navigation
fix(client)!: route manifests by namespace, cut ranges answered whole, and check URI objects - #21
Merged
Merged
Conversation
…, 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]>
There was a problem hiding this comment.
🟡 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
…r its namespace everywhere, and clamp an empty window Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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'scrates/cli/src/commands/gateway.rs.Changes
?ns=hint (the gateway pulls manifests with it), cached by hash and hint. A site's own entries take its host's namespace.text/html; charset=utf-8), not the bare blob'sapplication/octet-stream.get,headandresolveread<dir>as<dir>/index.html, as a site redirects it (entry()/head_site). Before, verification turned that redirect into NOT_FOUND.200(a page a site rewrites, a proxy that dropsRange) has the window cut from the body (sliceinsrc/verify.ts). A window past the end fails withRANGE_NOT_SATISFIABLE, as on a206. A range is still never verified.CONFIGbefore any request, instead of HASH_MISMATCH on a site-rewritten redirect.Content-Lengthis neither a lower bound norcontentLengthfor an encoded body.DecdnUriobjects are checked and normalised as their strings parse (an uppercase hash works; a bad one isBAD_URI).sendOk(http.ts) and oneconcat(bytes.ts) replace the copies; deadverifiedlogic is gone.Fake gateway: it gains a
namespacedmap (content found only under its?ns=) and a site directory redirect onGETandHEAD. It also resolves relativeLocations, keeping the method.Breaking
DecdnResponse.contentRange.lengthand.sizeare optional. A window cut from a body of unknown length (a rewritten page streams with none) holds itsoffsetalone.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
Content-Encodingcross-origin, so a page on another origin still cannot see it./_decdn/<h>/<dir>goes to<dir>/, which the URI parser refuses (a trailing/), so that path answers 400. The SDK's verified path fetches theindex.htmlentry directly and is unaffected.🤖 Generated with Claude Code