Skip to content

Commit e4508c0

Browse files
https://github.com/node-fetch/node-fetch/issues/83
1 parent 6c00532 commit e4508c0

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

‎src/sender/index.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,19 @@ export const sendActivity = async (
4343
);
4444

4545
const res = await fetch(inbox, signed);
46-
if (res.status != 202)
46+
if (!res.ok) {
47+
Log.error(
48+
`Sending activity ${activity.id} to ${inbox} failed : ${res.status} ${res.statusText}`,
49+
);
50+
51+
// https://github.com/node-fetch/node-fetch/issues/83
52+
// fix memory leak by reading the buffer
53+
const leak = await res.arrayBuffer();
54+
} else
4755
Log.verbose(
4856
`Sent activity ${activity.id} got response`,
4957
await res.text(),
5058
);
51-
if (!res.ok)
52-
Log.error(
53-
`Sending activity to ${target} failed : ${res.status} ${res.statusText}`,
54-
);
5559
}
5660
};
5761

‎src/util/activitypub/resolve.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ApCache } from "../../entity";
1111
import { WebfingerResponse } from "../../http/wellknown/webfinger";
1212
import { config } from "../config";
1313
import { createLogger } from "../log";
14-
import { USER_AGENT } from "./constants";
14+
import { ACTIVITY_JSON_ACCEPT, USER_AGENT } from "./constants";
1515
import { APError } from "./error";
1616
import { HttpSig } from "./httpsig";
1717
import { InstanceActor } from "./instanceActor";
@@ -59,6 +59,12 @@ export const resolveAPObject = async <T extends AnyAPObject>(
5959

6060
const json = await res.json();
6161

62+
const header = res.headers.get("content-type");
63+
if (!header || !ACTIVITY_JSON_ACCEPT.includes(header))
64+
throw new APError(
65+
`Fetched resource ${data} did not return an activitypub/jsonld content type`,
66+
);
67+
6268
if (!hasAPContext(json)) throw new APError("Object is not APObject");
6369

6470
if (!noCache)
@@ -94,6 +100,8 @@ export const doWebfingerOrFindTemplate = async (
94100
throw new APError(
95101
`Remote server sent code ${res.status} : ${res.statusText}`,
96102
);
103+
104+
// TODO: validation
97105
return await res.json();
98106
}
99107

0 commit comments

Comments
 (0)