MCPcopy Create free account
hub / github.com/CopilotKit/aimock / readBody

Function readBody

src/helpers.ts:1203–1235  ·  view source on GitHub ↗
(
  req: http.IncomingMessage,
  maxBytes: number = DEFAULT_MAX_BODY_BYTES,
)

Source from the content-addressed store, hash-verified

1201const DEFAULT_MAX_BODY_BYTES = 10 * 1024 * 1024; // 10 MB
1202
1203export function readBody(
1204 req: http.IncomingMessage,
1205 maxBytes: number = DEFAULT_MAX_BODY_BYTES,
1206): Promise<string> {
1207 return new Promise((resolve, reject) => {
1208 const chunks: Buffer[] = [];
1209 let totalBytes = 0;
1210 let settled = false;
1211 req.on("data", (chunk: Buffer) => {
1212 if (settled) return;
1213 totalBytes += chunk.length;
1214 if (totalBytes > maxBytes) {
1215 settled = true;
1216 req.destroy();
1217 reject(new Error(`Request body exceeded size limit of ${maxBytes} bytes`));
1218 return;
1219 }
1220 chunks.push(chunk);
1221 });
1222 req.on("end", () => {
1223 if (!settled) {
1224 settled = true;
1225 resolve(Buffer.concat(chunks).toString());
1226 }
1227 });
1228 req.on("error", (err) => {
1229 if (!settled) {
1230 settled = true;
1231 reject(err);
1232 }
1233 });
1234 });
1235}
1236
1237// ─── Pattern matching ─────────────────────────────────────────────────────
1238

Callers 7

handleRequestMethod · 0.85
handleRequestMethod · 0.85
handleRequestMethod · 0.85
handleRequestMethod · 0.85
handleControlAPIFunction · 0.85
handleCompletionsFunction · 0.85
handleHttpRequestFunction · 0.85

Calls 3

resolveFunction · 0.85
onMethod · 0.80
destroyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…