From a344e293f1b1fc32d4472995317057d4c6c54485 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 10 Mar 2026 18:02:12 -0700 Subject: [PATCH] Buffer request body before proxying to unix socket Streaming req.body through the double proxy (toes -> bun -> go) caused POST requests to fail. Buffer the body as an ArrayBuffer first so content-length is set correctly. Co-Authored-By: Claude Opus 4.6 --- src/proxy.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/proxy.ts b/src/proxy.ts index 727ba4e..b282a9f 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -8,7 +8,7 @@ export interface WsData { const upstreams = new Map, WebSocket>() export function createProxy(socketPath: string, isHealthy: () => boolean, isRunning: () => boolean) { - function proxyFetch(req: Request): Promise | Response { + async function proxyFetch(req: Request): Promise { const url = new URL(req.url) if (url.pathname === '/ok') { @@ -21,11 +21,12 @@ export function createProxy(socketPath: string, isHealthy: () => boolean, isRunn const hasBody = req.method !== 'GET' && req.method !== 'HEAD' const headers = new Headers(req.headers) headers.delete('accept-encoding') + const body = hasBody ? await req.arrayBuffer() : undefined return fetch(`http://localhost${url.pathname}${url.search}`, { method: req.method, headers, - body: hasBody ? req.body : undefined, + body, unix: socketPath, }).then((r) => { const respHeaders = new Headers(r.headers)