11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst http = require('http'); 51cb0ef41Sopenharmony_ciconst debug = require('util').debuglog('test'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst testResBody = 'other stuff!\n'; 81cb0ef41Sopenharmony_ciconst kMessageCount = 2; 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst server = http.createServer((req, res) => { 111cb0ef41Sopenharmony_ci for (let i = 0; i < kMessageCount; i++) { 121cb0ef41Sopenharmony_ci debug(`Server sending informational message #${i}...`); 131cb0ef41Sopenharmony_ci res.writeProcessing(); 141cb0ef41Sopenharmony_ci } 151cb0ef41Sopenharmony_ci debug('Server sending full response...'); 161cb0ef41Sopenharmony_ci res.writeHead(200, { 171cb0ef41Sopenharmony_ci 'Content-Type': 'text/plain', 181cb0ef41Sopenharmony_ci 'ABCD': '1' 191cb0ef41Sopenharmony_ci }); 201cb0ef41Sopenharmony_ci res.end(testResBody); 211cb0ef41Sopenharmony_ci}); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ciserver.listen(0, function() { 241cb0ef41Sopenharmony_ci const req = http.request({ 251cb0ef41Sopenharmony_ci port: this.address().port, 261cb0ef41Sopenharmony_ci path: '/world' 271cb0ef41Sopenharmony_ci }); 281cb0ef41Sopenharmony_ci req.end(); 291cb0ef41Sopenharmony_ci debug('Client sending request...'); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci let body = ''; 321cb0ef41Sopenharmony_ci let infoCount = 0; 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci req.on('information', () => { infoCount++; }); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci req.on('response', function(res) { 371cb0ef41Sopenharmony_ci // Check that all 102 Processing received before full response received. 381cb0ef41Sopenharmony_ci assert.strictEqual(infoCount, kMessageCount); 391cb0ef41Sopenharmony_ci assert.strictEqual(res.statusCode, 200, 401cb0ef41Sopenharmony_ci `Final status code was ${res.statusCode}, not 200.`); 411cb0ef41Sopenharmony_ci res.setEncoding('utf8'); 421cb0ef41Sopenharmony_ci res.on('data', function(chunk) { body += chunk; }); 431cb0ef41Sopenharmony_ci res.on('end', function() { 441cb0ef41Sopenharmony_ci debug('Got full response.'); 451cb0ef41Sopenharmony_ci assert.strictEqual(body, testResBody); 461cb0ef41Sopenharmony_ci assert.ok('abcd' in res.headers); 471cb0ef41Sopenharmony_ci server.close(); 481cb0ef41Sopenharmony_ci }); 491cb0ef41Sopenharmony_ci }); 501cb0ef41Sopenharmony_ci}); 51