Skip to content

Commit 591a4ae

Browse files
Fix: collect async iterable body before fetch, add debug logging
1 parent e5a2896 commit 591a4ae

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

index.html

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,15 +436,34 @@
436436
'Authorization': 'Nostr ' + token
437437
};
438438

439+
// Collect body if it's an async iterable
440+
let requestBody = body;
441+
if (body && typeof body[Symbol.asyncIterator] === 'function') {
442+
const chunks = [];
443+
for await (const chunk of body) {
444+
chunks.push(chunk);
445+
}
446+
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
447+
requestBody = new Uint8Array(totalLength);
448+
let offset = 0;
449+
for (const chunk of chunks) {
450+
requestBody.set(chunk, offset);
451+
offset += chunk.length;
452+
}
453+
}
454+
455+
console.log(`HTTP ${method} ${url}`, { bodySize: requestBody?.length });
456+
439457
// Make the request
440458
const res = await fetch(url, {
441459
method,
442460
headers: authHeaders,
443-
body
461+
body: requestBody
444462
});
445463

446464
// Return response in format isomorphic-git expects
447465
const responseBody = new Uint8Array(await res.arrayBuffer());
466+
console.log(`Response ${res.status}:`, { bodySize: responseBody.length });
448467

449468
return {
450469
url: res.url,

0 commit comments

Comments
 (0)