MCPcopy Create free account
hub / github.com/EvoMap/evolver / sendJson

Function sendJson

src/proxy/server/http.js:72–88  ·  view source on GitHub ↗
(res, status, body, extraHeaders = {})

Source from the content-addressed store, hash-verified

70}
71
72function sendJson(res, status, body, extraHeaders = {}) {
73 const payload = JSON.stringify(body);
74 const headers = {
75 'Content-Type': 'application/json',
76 'Content-Length': Buffer.byteLength(payload),
77 };
78 for (const [name, value] of Object.entries(extraHeaders || {})) {
79 if (value === undefined || value === null) continue;
80 const lower = String(name).toLowerCase();
81 if (lower === 'content-length' || lower === 'transfer-encoding' || lower === 'connection') continue;
82 const headerValue = Array.isArray(value) ? value.join(', ') : String(value);
83 if (/[\r\n]/.test(headerValue)) continue;
84 headers[name] = headerValue;
85 }
86 res.writeHead(status, headers);
87 res.end(payload);
88}
89
90function tryListen(server, port) {
91 return new Promise((resolve, reject) => {

Callers 1

_handleRequestMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected