MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / requestOn

Function requestOn

__tests__/ui-server-api.test.ts:42–68  ·  view source on GitHub ↗

* One request against a live server, with the loopback `Host` the boundary * wants. Written with `http.request` rather than `fetch` so the `Host` header * is ours to set — undici treats it as forbidden.

(port: number, requestPath: string, method = 'GET')

Source from the content-addressed store, hash-verified

40 * is ours to set — undici treats it as forbidden.
41 */
42function requestOn(port: number, requestPath: string, method = 'GET'): Promise<Response> {
43 return new Promise((resolve, reject) => {
44 const req = http.request(
45 {
46 host: '127.0.0.1',
47 port,
48 path: requestPath,
49 method,
50 headers: { Host: `127.0.0.1:${port}` },
51 setHost: false,
52 },
53 (res) => {
54 const chunks: Buffer[] = [];
55 res.on('data', (c: Buffer) => chunks.push(c));
56 res.on('end', () =>
57 resolve({
58 status: res.statusCode ?? 0,
59 headers: res.headers,
60 body: Buffer.concat(chunks).toString('utf-8'),
61 })
62 );
63 }
64 );
65 req.on('error', reject);
66 req.end();
67 });
68}
69
70/** The same, against the main fixture's server. */
71function request(requestPath: string, method = 'GET'): Promise<Response> {

Callers 3

requestFunction · 0.85
repoGetFunction · 0.85

Calls 4

pushMethod · 0.80
resolveFunction · 0.70
requestMethod · 0.65
onMethod · 0.65

Tested by

no test coverage detected