MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / rawHttpGet

Function rawHttpGet

packages/server/test/host-origin.e2e.test.ts:93–118  ·  view source on GitHub ↗

* Raw HTTP GET that lets us set an arbitrary `Host` header. Node's `fetch` * (undici) treats `Host` as a forbidden header and silently replaces it with * the URL host, so we drive `node:http` directly to exercise the Host check.

(
  url: string,
  headers: Record<string, string>,
)

Source from the content-addressed store, hash-verified

91 * the URL host, so we drive `node:http` directly to exercise the Host check.
92 */
93function rawHttpGet(
94 url: string,
95 headers: Record<string, string>,
96): Promise<{ status: number; body: string }> {
97 return new Promise((resolve, reject) => {
98 const u = new URL(url);
99 const req = httpRequest(
100 {
101 hostname: u.hostname,
102 port: u.port,
103 path: `${u.pathname}${u.search}`,
104 method: 'GET',
105 headers,
106 },
107 (res) => {
108 let body = '';
109 res.on('data', (chunk: Buffer) => {
110 body += chunk.toString();
111 });
112 res.on('end', () => resolve({ status: res.statusCode ?? 0, body }));
113 },
114 );
115 req.on('error', reject);
116 req.end();
117 });
118}
119
120function openConn(url: string, opts?: ConnectOptions): Promise<Conn> {
121 return new Promise((resolve, reject) => {

Callers 1

Calls 4

onMethod · 0.65
toStringMethod · 0.65
resolveFunction · 0.50
endMethod · 0.45

Tested by

no test coverage detected