Strip content-encoding/length from Go responses

Go server always sends gzip regardless of accept-encoding. Bun
decompresses it automatically but leaves the content-encoding
header. Strip it so the toes proxy doesn't try to decompress
the already-decompressed response.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Corey Johnson 2026-03-10 19:11:37 -07:00
parent 74155d3d0a
commit 08e80a2f92

View File

@ -20,14 +20,19 @@ export function createProxy(socketPath: string, isHealthy: () => boolean, isRunn
const hasBody = req.method !== 'GET' && req.method !== 'HEAD' const hasBody = req.method !== 'GET' && req.method !== 'HEAD'
const body = hasBody ? await req.arrayBuffer() : undefined const body = hasBody ? await req.arrayBuffer() : undefined
const headers = new Headers(req.headers)
headers.delete('accept-encoding')
return fetch(`http://localhost${url.pathname}${url.search}`, { return fetch(`http://localhost${url.pathname}${url.search}`, {
method: req.method, method: req.method,
headers, headers: req.headers,
body, body,
unix: socketPath, unix: socketPath,
}).then((r) => {
// Bun auto-decompresses gzip but leaves content-encoding header.
// Strip it so the next proxy layer doesn't try to decompress again.
const headers = new Headers(r.headers)
headers.delete('content-encoding')
headers.delete('content-length')
return new Response(r.body, { status: r.status, headers })
}).catch((e) => { }).catch((e) => {
console.error('Proxy error:', e) console.error('Proxy error:', e)
return new Response('Tronbyt server is not responding', { status: 502 }) return new Response('Tronbyt server is not responding', { status: 502 })