drop content-encoding when the body is rewritten

`.text()` decompresses, so the rewritten HTML goes back plain — while the
headers still said `content-encoding: gzip`. The next hop believed the header,
tried to gunzip plain text, and failed with ZlibError.

Which surfaced as "gitea unreachable": a 502 naming nothing, while a direct
curl to the sidecar returned 200 the whole time.
This commit is contained in:
officer
2026-08-19 09:13:19 +00:00
parent e3f673ecb9
commit dcfcf4e503
+5
View File
@@ -307,7 +307,12 @@ const server = Bun.serve({
// `appSubUrl`, patched below by the same pass, is what makes Gitea's own scripts correct.
if ((out.get('content-type') ?? '').includes('text/html')) {
const body = rewriteHtml(await upstream.text(), base, origins);
// BOTH of these, and the second is not optional. `.text()` has already decompressed, so the
// body being returned is plain — while `out` still carries Gitea's `content-encoding: gzip`.
// The next hop believes that header, tries to gunzip plain text, and fails with ZlibError:
// a 502 that names nothing and looks exactly like the sidecar being unreachable.
out.delete('content-length'); // the body just changed length
out.delete('content-encoding'); // and is no longer compressed
return new Response(body, { status: upstream.status, headers: out });
}
}