| 88 | private res: http.IncomingMessage | null = null; |
| 89 | |
| 90 | open(requestPath = '/api/events'): Promise<void> { |
| 91 | return new Promise((resolve, reject) => { |
| 92 | const req = http.request( |
| 93 | { |
| 94 | host: '127.0.0.1', |
| 95 | port: server.port, |
| 96 | path: requestPath, |
| 97 | method: 'GET', |
| 98 | headers: { Host: `127.0.0.1:${server.port}`, Accept: 'text/event-stream' }, |
| 99 | setHost: false, |
| 100 | }, |
| 101 | (res) => { |
| 102 | this.res = res; |
| 103 | this.status = res.statusCode ?? 0; |
| 104 | this.contentType = res.headers['content-type']; |
| 105 | res.setEncoding('utf-8'); |
| 106 | res.on('data', (chunk: string) => this.ingest(chunk)); |
| 107 | resolve(); |
| 108 | } |
| 109 | ); |
| 110 | this.req = req; |
| 111 | req.on('error', reject); |
| 112 | req.end(); |
| 113 | }); |
| 114 | } |
| 115 | |
| 116 | private ingest(chunk: string): void { |
| 117 | this.buffer += chunk; |