| 414 | } |
| 415 | |
| 416 | httpGet(host, path, hostHeaderValue) { |
| 417 | this._logger.log('[test]', `Testing ${path}`); |
| 418 | const headers = hostHeaderValue ? { 'Host': hostHeaderValue } : null; |
| 419 | return this.portPromise.then((port) => new Promise((resolve, reject) => { |
| 420 | const req = http.get({ host, port, family: 4, path, headers }, (res) => { |
| 421 | let response = ''; |
| 422 | res.setEncoding('utf8'); |
| 423 | res |
| 424 | .on('data', (data) => response += data.toString()) |
| 425 | .on('end', () => { |
| 426 | resolve(response); |
| 427 | }); |
| 428 | }); |
| 429 | req.on('error', reject); |
| 430 | })).then((response) => { |
| 431 | try { |
| 432 | return JSON.parse(response); |
| 433 | } catch (e) { |
| 434 | e.body = response; |
| 435 | throw e; |
| 436 | } |
| 437 | }); |
| 438 | } |
| 439 | |
| 440 | async sendUpgradeRequest() { |
| 441 | const response = await this.httpGet(null, '/json/list'); |