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

Function rawGet

packages/server/test/auth-middleware.e2e.test.ts:126–155  ·  view source on GitHub ↗

* Raw HTTP GET that lets us spoof the `Host` header. Node's `http.request` * honors an explicit `headers.Host`, whereas `fetch` (undici) treats `Host` as * a forbidden header and drops it.

(
  port: number,
  path: string,
  headers: Record<string, string>,
)

Source from the content-addressed store, hash-verified

124 * a forbidden header and drops it.
125 */
126function rawGet(
127 port: number,
128 path: string,
129 headers: Record<string, string>,
130): Promise<{ status: number; body: unknown }> {
131 return new Promise((resolve, reject) => {
132 const req = httpRequest(
133 { host: '127.0.0.1', port, path, method: 'GET', headers },
134 (res) => {
135 let data = '';
136 res.setEncoding('utf8');
137 res.on('data', (chunk: string) => {
138 data += chunk;
139 });
140 res.on('end', () => {
141 try {
142 resolve({
143 status: res.statusCode ?? 0,
144 body: JSON.parse(data) as unknown,
145 });
146 } catch (err) {
147 reject(err);
148 }
149 });
150 },
151 );
152 req.on('error', reject);
153 req.end();
154 });
155}
156
157describe('/asyncapi.json serverHost (M2.3 Host-reflection fix)', () => {
158 afterEach(async () => {

Callers 1

Calls 4

rejectFunction · 0.85
onMethod · 0.65
resolveFunction · 0.50
endMethod · 0.45

Tested by

no test coverage detected