/** `request` with `headers` in place of its own, its body passed through as the same stream. Bun's * `new Request(request, { headers })` drops a streamed body (one a node:http server gives as `Readable.toWeb`, duplex * half): reading the copy waits forever, and so does the twin that reads it. Measured on Bun 1.3.10; rebuilding from * the URL with `body: request.body` keeps it readable. */ export function withHeaders(request: Request, headers: Headers): Request { const body = request.method === 'GET' || request.method === 'HEAD' ? null : request.body; return new Request(request.url, { method: request.method, headers, body, signal: request.signal, redirect: request.redirect, ...(body ? { duplex: 'half' } : {}) } as RequestInit); }