* 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>, )
| 124 | * a forbidden header and drops it. |
| 125 | */ |
| 126 | function 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 | |
| 157 | describe('/asyncapi.json serverHost (M2.3 Host-reflection fix)', () => { |
| 158 | afterEach(async () => { |
no test coverage detected