11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst http = require('http'); 51cb0ef41Sopenharmony_ciconst Countdown = require('../common/countdown'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst expectedHeadersMultipleWrites = { 81cb0ef41Sopenharmony_ci 'connection': 'close', 91cb0ef41Sopenharmony_ci 'transfer-encoding': 'chunked', 101cb0ef41Sopenharmony_ci}; 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst expectedHeadersEndWithData = { 131cb0ef41Sopenharmony_ci 'connection': 'close', 141cb0ef41Sopenharmony_ci 'content-length': String('hello world'.length) 151cb0ef41Sopenharmony_ci}; 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciconst expectedHeadersEndNoData = { 181cb0ef41Sopenharmony_ci 'connection': 'close', 191cb0ef41Sopenharmony_ci 'content-length': '0', 201cb0ef41Sopenharmony_ci}; 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ciconst countdown = new Countdown(3, () => server.close()); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ciconst server = http.createServer(function(req, res) { 261cb0ef41Sopenharmony_ci res.removeHeader('Date'); 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci switch (req.url.substr(1)) { 291cb0ef41Sopenharmony_ci case 'multiple-writes': 301cb0ef41Sopenharmony_ci assert.deepStrictEqual(req.headers, expectedHeadersMultipleWrites); 311cb0ef41Sopenharmony_ci res.write('hello'); 321cb0ef41Sopenharmony_ci res.end('world'); 331cb0ef41Sopenharmony_ci break; 341cb0ef41Sopenharmony_ci case 'end-with-data': 351cb0ef41Sopenharmony_ci assert.deepStrictEqual(req.headers, expectedHeadersEndWithData); 361cb0ef41Sopenharmony_ci res.end('hello world'); 371cb0ef41Sopenharmony_ci break; 381cb0ef41Sopenharmony_ci case 'empty': 391cb0ef41Sopenharmony_ci assert.deepStrictEqual(req.headers, expectedHeadersEndNoData); 401cb0ef41Sopenharmony_ci res.end(); 411cb0ef41Sopenharmony_ci break; 421cb0ef41Sopenharmony_ci default: 431cb0ef41Sopenharmony_ci throw new Error('Unreachable'); 441cb0ef41Sopenharmony_ci } 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci countdown.dec(); 471cb0ef41Sopenharmony_ci}); 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ciserver.listen(0, function() { 501cb0ef41Sopenharmony_ci let req; 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci req = http.request({ 531cb0ef41Sopenharmony_ci port: this.address().port, 541cb0ef41Sopenharmony_ci method: 'POST', 551cb0ef41Sopenharmony_ci path: '/multiple-writes' 561cb0ef41Sopenharmony_ci }); 571cb0ef41Sopenharmony_ci req.removeHeader('Date'); 581cb0ef41Sopenharmony_ci req.removeHeader('Host'); 591cb0ef41Sopenharmony_ci req.write('hello '); 601cb0ef41Sopenharmony_ci req.end('world'); 611cb0ef41Sopenharmony_ci req.on('response', function(res) { 621cb0ef41Sopenharmony_ci assert.deepStrictEqual(res.headers, expectedHeadersMultipleWrites); 631cb0ef41Sopenharmony_ci }); 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci req = http.request({ 661cb0ef41Sopenharmony_ci port: this.address().port, 671cb0ef41Sopenharmony_ci method: 'POST', 681cb0ef41Sopenharmony_ci path: '/end-with-data' 691cb0ef41Sopenharmony_ci }); 701cb0ef41Sopenharmony_ci req.removeHeader('Date'); 711cb0ef41Sopenharmony_ci req.removeHeader('Host'); 721cb0ef41Sopenharmony_ci req.end('hello world'); 731cb0ef41Sopenharmony_ci req.on('response', function(res) { 741cb0ef41Sopenharmony_ci assert.deepStrictEqual(res.headers, expectedHeadersEndWithData); 751cb0ef41Sopenharmony_ci }); 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci req = http.request({ 781cb0ef41Sopenharmony_ci port: this.address().port, 791cb0ef41Sopenharmony_ci method: 'POST', 801cb0ef41Sopenharmony_ci path: '/empty' 811cb0ef41Sopenharmony_ci }); 821cb0ef41Sopenharmony_ci req.removeHeader('Date'); 831cb0ef41Sopenharmony_ci req.removeHeader('Host'); 841cb0ef41Sopenharmony_ci req.end(); 851cb0ef41Sopenharmony_ci req.on('response', function(res) { 861cb0ef41Sopenharmony_ci assert.deepStrictEqual(res.headers, expectedHeadersEndNoData); 871cb0ef41Sopenharmony_ci }); 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ci}); 90