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

Method handleRequest

src/vector-mock.ts:75–116  ·  view source on GitHub ↗
(
    req: http.IncomingMessage,
    res: http.ServerResponse,
    pathname: string,
  )

Source from the content-addressed store, hash-verified

73 // ---- Mountable interface ----
74
75 async handleRequest(
76 req: http.IncomingMessage,
77 res: http.ServerResponse,
78 pathname: string,
79 ): Promise<boolean> {
80 // Only consume the request body for methods that carry a body,
81 // avoiding double-consumption when the route doesn't match.
82 let parsed: Record<string, unknown> = {};
83 if (req.method !== "GET" && req.method !== "DELETE" && req.method !== "HEAD") {
84 const body = await readBody(req);
85 try {
86 if (body) parsed = JSON.parse(body);
87 } catch (parseErr) {
88 const detail = parseErr instanceof Error ? parseErr.message : "unknown";
89 res.writeHead(400, { "Content-Type": "application/json" });
90 res.end(JSON.stringify({ error: `Malformed JSON body: ${detail}` }));
91 return true;
92 }
93 }
94
95 const handled = this.requestHandler(req, res, pathname, parsed);
96
97 // Record vector operation metric
98 if (handled && this.registry) {
99 const { operation, provider } = classifyVectorRequest(req.method ?? "GET", pathname);
100 this.registry.incrementCounter("aimock_vector_requests_total", { operation, provider });
101 }
102
103 // Journal the request after the handler completes
104 if (handled && this.journal) {
105 this.journal.add({
106 method: req.method ?? "GET",
107 path: req.url ?? "/",
108 headers: flattenHeaders(req.headers),
109 body: null,
110 service: "vector",
111 response: { status: res.statusCode, fixture: null },
112 });
113 }
114
115 return handled;
116 }
117
118 health(): { status: string; collections: number } {
119 return {

Callers

nothing calls this directly

Calls 6

readBodyFunction · 0.85
classifyVectorRequestFunction · 0.85
flattenHeadersFunction · 0.85
endMethod · 0.80
incrementCounterMethod · 0.80
addMethod · 0.80

Tested by

no test coverage detected