From 37909adf47a7bf2c779086cd87c05364d5e1aa44 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Wed, 1 Jul 2026 20:30:29 +0700 Subject: [PATCH] fix: avoid duplicate Content-Type header in fetch402 When a body is passed it is sent as JSON, so we default the Content-Type header. The agent isn't required to set the header itself but might do so anyway (in any casing), which previously produced two Content-Type headers. Only add our default when one isn't already present. Fixes https://github.com/getAlby/cli/issues/47 Co-Authored-By: Claude Opus 4.8 --- src/tools/lightning/fetch.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/tools/lightning/fetch.ts b/src/tools/lightning/fetch.ts index 6096c48..c61eda1 100644 --- a/src/tools/lightning/fetch.ts +++ b/src/tools/lightning/fetch.ts @@ -19,10 +19,17 @@ export async function fetch402(client: NWCClient, params: Fetch402Params) { if (method && method !== "GET" && method !== "HEAD") { requestOptions.body = params.body; - requestOptions.headers = { - "Content-Type": "application/json", - ...params.headers, - }; + // A body is always passed as JSON, so default the Content-Type. The agent + // isn't required to set the header itself but might do so anyway, so only + // add our default when it's absent to avoid a duplicate Content-Type. + const headers = { ...params.headers }; + const hasContentType = Object.keys(headers).some( + (key) => key.toLowerCase() === "content-type", + ); + if (!hasContentType) { + headers["Content-Type"] = "application/json"; + } + requestOptions.headers = headers; } else if (params.headers) { requestOptions.headers = params.headers; }