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

Function request

__tests__/ui-server.test.ts:48–72  ·  view source on GitHub ↗

* One request with full control over the request line and headers. * * `setHost: false` stops node from adding its own `Host`, and `path` is sent * verbatim — so a traversal case really does put `/../../x` on the wire.

(
  port: number,
  requestPath: string,
  options: { method?: string; headers?: Record<string, string> } = {}
)

Source from the content-addressed store, hash-verified

46 * verbatim — so a traversal case really does put `/../../x` on the wire.
47 */
48function request(
49 port: number,
50 requestPath: string,
51 options: { method?: string; headers?: Record<string, string> } = {}
52): Promise<Response> {
53 return new Promise((resolve, reject) => {
54 const headers: Record<string, string> = { Host: `127.0.0.1:${port}`, ...options.headers };
55 const req = http.request(
56 { host: '127.0.0.1', port, path: requestPath, method: options.method ?? 'GET', headers, setHost: false },
57 (res) => {
58 const chunks: Buffer[] = [];
59 res.on('data', (c: Buffer) => chunks.push(c));
60 res.on('end', () =>
61 resolve({
62 status: res.statusCode ?? 0,
63 headers: res.headers,
64 body: Buffer.concat(chunks).toString('utf-8'),
65 })
66 );
67 }
68 );
69 req.on('error', reject);
70 req.end();
71 });
72}
73
74/** A failed `listen()` as node reports it. */
75function bindError(code: string, port: number): NodeJS.ErrnoException {

Callers 1

ui-server.test.tsFile · 0.70

Calls 4

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

Tested by

no test coverage detected