diff --git a/src/activity.ts b/src/activity.ts index 3a121f5..08e912c 100644 --- a/src/activity.ts +++ b/src/activity.ts @@ -201,6 +201,7 @@ export const sendAccept = async (user: User, followId: string, follower: string, }; const payload = JSON.stringify(activity, null, 4); + console.log("Accept payload:", payload); const init: RequestInit = { method: "POST", body: payload }; const init2 = { privateKey: user.private_key, keyId: getKeyId(user.nickname) }; @@ -208,7 +209,7 @@ export const sendAccept = async (user: User, followId: string, follower: string, const result = await signedFetch(inbox, init, init2); console.log("response status:", result.status); const response = await streamToString(result.body as ReadableStream); - console.log("body:", response); + console.log("Response body:", response); }; export const sendAll = async (keyId: string, privateKey: string, activity: Record | string, inboxes: string[]) => { diff --git a/src/net.ts b/src/net.ts index e24ad3b..046ddce 100644 --- a/src/net.ts +++ b/src/net.ts @@ -25,7 +25,7 @@ export const signedFetch = async (url: string, init: RequestInit, signedInit: Si ["Content-Type", `application/ld+json; profile="${CONTEXT}"`] ]; - if (signedInit.digest) { + if (signedInit.digest && init.body) { signedHeaders.push(["Digest", signedInit.digest]); } else if (init.body) { @@ -34,6 +34,9 @@ export const signedFetch = async (url: string, init: RequestInit, signedInit: Si } else throw "unsupported body type"; } + else { + throw "no body provided"; + } const signer = new Sha256Signer({ privateKey: signedInit.privateKey, @@ -62,7 +65,8 @@ export const signedFetch = async (url: string, init: RequestInit, signedInit: Si } else throw "unsupported headers type"; // Lazy. - console.log(init.body, Headers.toString()); + console.log("Headers:"); + newHeaders.forEach((header) => console.log(header)); return fetch(url, { ...init,