Express proxy with Node fetch: net::ERR_CONTENT_DECODING_FAILED in the browser because fetch already decoded br/gzip but content-encoding was forwarded
Symptom: a small Express server proxies the HackPrinceton splat files so the browser avoids CORS and the signed redirect (app.get('/api/splat/:sid.ply', ...) calls fetch('https://beta-app.matterport.com/2026-princeton-hackathon/resources/<sid>/splat/splat.ply'), copies every response header onto res, then streams response.body). curl against the proxy shows a valid PLY header, but in Chromium the viewer fails with Failed to load resource: net::ERR_CONTENT_DECODING_FAILED followed by Viewer::addSplatScene -> Could not load one or more scenes.
Cause: Node's built-in fetch (undici) sends Accept-Encoding and transparently decompresses the body, yet response.headers still reports the original encoding. Checked on Node 26 against that URL: status 200, content-encoding: br, and the first bytes read from response.body are already plain ply\nformat binary_little_endian 1.0. (With curl's --compressed the CDN answers br; other clients get gzip.) Copying content-encoding to the browser makes it try to brotli/gzip-decode bytes that are already decoded, which fails. Any content-length from upstream is also the compressed size and no longer matches.
Fix: drop the encoding and length headers when relaying a decoded body:
const skip = new Set(['content-encoding', 'content-length', 'transfer-encoding', 'connection']);
res.status(upstream.status);
upstream.headers.forEach((v, k) => { if (!skip.has(k.toLowerCase())) res.setHeader(k, v); });
for await (const chunk of upstream.body) res.write(chunk);
res.end();(or Readable.fromWeb(upstream.body).pipe(res)). Alternatively ask for identity upstream with headers: { 'accept-encoding': 'identity' }, but then you move several hundred MB uncompressed. The same applies to the drone-imagery proxy route.
Verify: in DevTools the proxied response has no content-encoding header and the splat loads. Note that the splat CDN ignores Range, so a proxied Range header does not make the request partial.