File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import { ApCache } from "../../entity";
1111import { WebfingerResponse } from "../../http/wellknown/webfinger" ;
1212import { config } from "../config" ;
1313import { createLogger } from "../log" ;
14- import { USER_AGENT } from "./constants" ;
14+ import { ACTIVITY_JSON_ACCEPT , USER_AGENT } from "./constants" ;
1515import { APError } from "./error" ;
1616import { HttpSig } from "./httpsig" ;
1717import { 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
You can’t perform that action at this time.
0 commit comments