From dcfcf4e503dfe36a327f5d0810860f59e84a46da Mon Sep 17 00:00:00 2001 From: officer Date: Wed, 19 Aug 2026 09:13:19 +0000 Subject: [PATCH] drop content-encoding when the body is rewritten MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `.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. --- sidecar/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sidecar/index.ts b/sidecar/index.ts index 9d09ecf..f257a5f 100644 --- a/sidecar/index.ts +++ b/sidecar/index.ts @@ -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 }); } }