* 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>, )
| 91 | * the URL host, so we drive `node:http` directly to exercise the Host check. |
| 92 | */ |
| 93 | function 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 | |
| 120 | function openConn(url: string, opts?: ConnectOptions): Promise<Conn> { |
| 121 | return new Promise((resolve, reject) => { |
no test coverage detected