MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / handle_content_length_frame

Function handle_content_length_frame

src/mcp/mcp.c:6203–6232  ·  view source on GitHub ↗

Handle a Content-Length-framed message (LSP-style transport). * Reads headers, body, processes request, writes framed response. */

Source from the content-addressed store, hash-verified

6201/* Handle a Content-Length-framed message (LSP-style transport).
6202 * Reads headers, body, processes request, writes framed response. */
6203static void handle_content_length_frame(cbm_mcp_server_t *srv, FILE *in, FILE *out, char **line,
6204 size_t *cap, int content_len) {
6205 /* Skip blank line(s) between header and body */
6206 while (cbm_getline(line, cap, in) > 0) {
6207 size_t hlen = strlen(*line);
6208 while (hlen > 0 && ((*line)[hlen - SKIP_ONE] == '\n' || (*line)[hlen - SKIP_ONE] == '\r')) {
6209 (*line)[--hlen] = '\0';
6210 }
6211 if (hlen == 0) {
6212 break;
6213 }
6214 }
6215
6216 char *body = malloc((size_t)content_len + SKIP_ONE);
6217 if (!body) {
6218 return;
6219 }
6220 size_t nread = fread(body, SKIP_ONE, (size_t)content_len, in);
6221 body[nread] = '\0';
6222
6223 char *resp = cbm_mcp_server_handle(srv, body);
6224 free(body);
6225
6226 if (resp) {
6227 size_t rlen = strlen(resp);
6228 (void)fprintf(out, "Content-Length: %zu\r\n\r\n%s", rlen, resp);
6229 (void)fflush(out);
6230 free(resp);
6231 }
6232}
6233
6234#ifndef _WIN32
6235/* Unix 3-phase poll: non-blocking fd check, FILE* buffer peek, blocking poll.

Callers 1

cbm_mcp_server_runFunction · 0.85

Calls 2

cbm_getlineFunction · 0.85
cbm_mcp_server_handleFunction · 0.85

Tested by

no test coverage detected