Skip to content

fix(gateway): expose Content-Encoding to cross-origin readers - #2870

Merged
alpergundogdu merged 4 commits into
mainfrom
fix/2817-expose-content-encoding
Nov 11, 2026
Merged

alpergundogdu merged 4 commits into
mainfrom
fix/2817-expose-content-encoding

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2817

A compressing proxy in front of a public gateway sets Content-Encoding, and Content-Length then counts the encoded bytes. Content-Encoding is not CORS-safelisted, so a page on another origin could not see it, and @decdn/client treated Content-Length as a lower bound on a decoded body.

Changes

SDK PRs merge first

Each adds Content-Encoding to its fake gateway's EXPOSED list and a public contract test that access-control-expose-headers includes content-encoding. The test is declared only for gateways that carry this change (shippedAfter("0.3.1") / shipped_after("0.3.1"), driven by DECDN_CONTRACT_RELEASE from decdn-contract.sh --tag), so the SDKs' release-gateway runs against v0.3.0 and v0.3.1 keep passing. The gateway floors stay as they are.

Merge both SDK PRs before this one. If either head changes, move its pin here. Both SDK repos squash-merge, so after they merge, move both pins to the squash commits on each SDK main and let the SDK contract jobs rerun before merging this PR.

Tests

  • cargo fmt -- --check: pass.
  • cargo clippy --workspace --all-targets --all-features -- -D warnings: pass.
  • cargo nextest run -p decdn-cli: 1253 passed.

🤖 Generated with Claude Code

A proxy in front of a public gateway can encode the body, and then
Content-Length counts the encoded bytes. Content-Encoding is not
CORS-safelisted, so a page on another origin could not tell. The public
CORS headers now expose it, and both SDK pins move to the commits that
mirror the list in their fake gateways and assert it in the contract suite.

Closes #2817

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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.

Note

Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

🟡 Changes recommended

A remaining readability nit was flagged in adr/appendix-gateway.md at line 220 for an overly long unwrapped line that should be wrapped to match the document’s formatting conventions.

1 open issue
What changed in this PR

Updates the public gateway’s CORS exposed-headers configuration so cross-origin clients can read Content-Encoding, enabling SDKs to correctly interpret Content-Length when responses are compressed by an upstream proxy/CDN.

Changes:

  • Expose Content-Encoding via Access-Control-Expose-Headers for public gateway responses.
  • Update public CORS contract tests to expect Content-Encoding as readable cross-origin.
  • Document the rationale in the gateway appendix and bump pinned TypeScript/Python SDK contract SHAs.
File Description
crates/​cli/​src/​commands/​gateway/​tests.rs Updates the canonical readable-header set used by public CORS tests to include Content-Encoding.
crates/​cli/​src/​commands/​gateway.rs Adds Content-Encoding to the public exposed-header list used to build Access-Control-Expose-Headers for public gateway responses.
adr/​appendix-gateway.md Documents that Content-Encoding is exposed for cross-origin reads and explains why it’s needed to interpret Content-Length under compression.
.github/​sdk-typescript.sha Bumps the pinned sdk-typescript commit to the revision that aligns its gateway contract expectations with exposing content-encoding.
.github/​sdk-python.sha Bumps the pinned sdk-python commit to the revision that aligns its gateway contract expectations with exposing content-encoding.

Review effort: Balanced

Comment thread adr/appendix-gateway.md Resolved
@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 5bd3d25 fix/2817-expose-cont... 84e5ae0 +/-
77% 77% 0%
View coverage of the 1 most impacted file.
File main 5bd3d25 fix/2817-expose-cont... 84e5ae0 +/-
crates/client/src/lib.rs 90% 89% -1%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.

alpergundogdu added a commit to decdn/sdk-typescript 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]>
@alpergundogdu
alpergundogdu merged commit 6fe9583 into main Nov 11, 2026
37 checks passed
@alpergundogdu
alpergundogdu deleted the fix/2817-expose-content-encoding branch November 11, 2026 19:47
@alpergundogdu
alpergundogdu requested a review from thiras November 11, 2026 19:57
alpergundogdu added a commit to decdn/sdk-python 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), so a page on another origin can tell that a proxy in
front encoded the body.

## Changes

- `tests/fake_gateway.py` and `tests/unit/test_fake_gateway.py`:
`EXPOSED` lists `Content-Encoding` after `Content-Length`, as the
gateway does.
- `tests/contract/test_public.py`: a blob read with an `Origin` finds
`content-encoding` and `content-length` in
`access-control-expose-headers`.
- `tests/contract/fixture.py`: `shipped_after(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 carry everything.
- The new test is declared inside `if shipped_after("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. This
is the same gate as decdn/sdk-typescript#25.

## Order

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

## Gateway floor

`gateway-floor` stays as is: the SDK code does not change, and the
weekly release-gateway runs do not collect the new test.

## Tests

- `uv run ruff check .`, `uv run ruff format --check .`, `uv run mypy`,
`shellcheck scripts/decdn-contract.sh`: pass.
- `uv run pytest tests/unit tests/contract`: 354 passed.
- With `DECDN_CONTRACT_RELEASE=0.3.1` the new test is not collected;
with 0.3.2 or 0.4.0-rc.1 it runs and passes.
- `tests/scripts/test_decdn_contract.py` fails locally on macOS,
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.

gateway: expose Content-Encoding to cross-origin readers on a public gateway

2 participants