fix(cdn): serve pre-compressed R2 bodies with encodeBody manual

Second half of the staging Firefox boot failure: the bucket stores
artifacts brotli-compressed (publish-wasm --compress br) with
Content-Encoding in the object metadata, but the worker returned them
with the default encodeBody:'automatic' — the runtime drops a user-set
Content-Encoding and re-negotiates, and on workers.dev that served the
raw brotli bytes with NO encoding header. The editor <script> tags
loaded binary garbage: Firefox fires onload and silently executes
nothing, so wxElementRegistry/Module never appeared even after the 206
fix. encodeBody:'manual' passes the header+body through untouched
(verified against local workerd with a br-encoded seeded object).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PmR6goSk7JC17h7fkgGvHG
This commit is contained in:
Gergő Törcsvári 2026-08-17 14:50:15 +02:00
commit 2b9ba1a6db
No known key found for this signature in database
GPG key ID: 8E75F2CDE64E5322

View file

@ -86,9 +86,21 @@ export default {
headers.set("Content-Length", String(object.size));
}
// The bucket stores artifacts PRE-COMPRESSED (publish-wasm --compress br,
// Content-Encoding in the object metadata). `encodeBody: "manual"` tells
// the runtime the body already matches the Content-Encoding header, so it
// passes both through untouched. The default "automatic" mode DROPS a
// user-set Content-Encoding and re-negotiates against the client's
// Accept-Encoding — behind prod's custom-domain edge that happened to
// round-trip, but on workers.dev it served the raw brotli bytes with NO
// encoding header: binary garbage where the browser expected JS/wasm.
// Firefox executed the garbage <script> to nothing (silently — onload
// still fires), leaving the editor glue inert: the second half of the
// "runtime did not initialize (no FS)" staging boot failure.
return new Response(request.method === "HEAD" ? null : object.body, {
status,
headers,
encodeBody: "manual",
});
},
};