MCPcopy Create free account
hub / github.com/avoidwork/tenso / payload

Function payload

src/middleware/payload.js:12–40  ·  view source on GitHub ↗
(req, res, next)

Source from the content-addressed store, hash-verified

10 * @returns {void}
11 */
12export function payload (req, res, next) {
13 if (hasBody(req.method) && req.headers?.[HEADER_CONTENT_TYPE]?.includes(MULTIPART) === false) {
14 const max = req.server.maxBytes;
15 let body = EMPTY,
16 invalid = false;
17
18 req.setEncoding(UTF8);
19
20 req.on(DATA, data => {
21 if (invalid === false) {
22 body += data;
23
24 if (max > INT_0 && Buffer.byteLength(body) > max) {
25 invalid = true;
26 res.error(INT_413);
27 }
28 }
29 });
30
31 req.on(END, () => {
32 if (invalid === false) {
33 req.body = body;
34 next();
35 }
36 });
37 } else {
38 next();
39 }
40}

Callers 1

Calls 1

hasBodyFunction · 0.90

Tested by

no test coverage detected