MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / readBody

Function readBody

yaml-flow-editor/vite.config.ts:31–47  ·  view source on GitHub ↗
(req: IncomingMessage, limitBytes = 2 * 1024 * 1024)

Source from the content-addressed store, hash-verified

29}
30
31function readBody(req: IncomingMessage, limitBytes = 2 * 1024 * 1024): Promise<string> {
32 return new Promise((resolve, reject) => {
33 let total = 0
34 const chunks: Buffer[] = []
35 req.on('data', (chunk: Buffer) => {
36 total += chunk.length
37 if (total > limitBytes) {
38 reject(new Error('Request body too large'))
39 req.destroy()
40 return
41 }
42 chunks.push(chunk)
43 })
44 req.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')))
45 req.on('error', reject)
46 })
47}
48
49function writeJson(res: ServerResponse, status: number, payload: unknown) {
50 res.statusCode = status

Callers 2

proxyHttpFunction · 0.85
configureServerFunction · 0.85

Calls 1

destroyMethod · 0.80

Tested by

no test coverage detected