11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// TODO@PI: Run all tests 41cb0ef41Sopenharmony_ciconst common = require('../common'); 51cb0ef41Sopenharmony_ciconst assert = require('assert'); 61cb0ef41Sopenharmony_ciconst { createServer, request } = require('http'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst server = createServer( 91cb0ef41Sopenharmony_ci { uniqueHeaders: ['x-res-b', 'x-res-d', 'x-res-y'] }, 101cb0ef41Sopenharmony_ci common.mustCall((req, res) => { 111cb0ef41Sopenharmony_ci const host = `127.0.0.1:${server.address().port}`; 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci assert.deepStrictEqual(req.rawHeaders, [ 141cb0ef41Sopenharmony_ci 'connection', 'close', 151cb0ef41Sopenharmony_ci 'X-Req-a', 'eee', 161cb0ef41Sopenharmony_ci 'X-Req-a', 'fff', 171cb0ef41Sopenharmony_ci 'X-Req-a', 'ggg', 181cb0ef41Sopenharmony_ci 'X-Req-a', 'hhh', 191cb0ef41Sopenharmony_ci 'X-Req-b', 'iii; jjj; kkk; lll', 201cb0ef41Sopenharmony_ci 'Host', host, 211cb0ef41Sopenharmony_ci 'Transfer-Encoding', 'chunked', 221cb0ef41Sopenharmony_ci ]); 231cb0ef41Sopenharmony_ci assert.deepStrictEqual(req.headers, { 241cb0ef41Sopenharmony_ci 'connection': 'close', 251cb0ef41Sopenharmony_ci 'x-req-a': 'eee, fff, ggg, hhh', 261cb0ef41Sopenharmony_ci 'x-req-b': 'iii; jjj; kkk; lll', 271cb0ef41Sopenharmony_ci host, 281cb0ef41Sopenharmony_ci 'transfer-encoding': 'chunked' 291cb0ef41Sopenharmony_ci }); 301cb0ef41Sopenharmony_ci assert.deepStrictEqual(req.headersDistinct, { 311cb0ef41Sopenharmony_ci 'connection': ['close'], 321cb0ef41Sopenharmony_ci 'x-req-a': ['eee', 'fff', 'ggg', 'hhh'], 331cb0ef41Sopenharmony_ci 'x-req-b': ['iii; jjj; kkk; lll'], 341cb0ef41Sopenharmony_ci 'host': [host], 351cb0ef41Sopenharmony_ci 'transfer-encoding': ['chunked'] 361cb0ef41Sopenharmony_ci }); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci req.on('end', function() { 391cb0ef41Sopenharmony_ci assert.deepStrictEqual(req.rawTrailers, [ 401cb0ef41Sopenharmony_ci 'x-req-x', 'xxx', 411cb0ef41Sopenharmony_ci 'x-req-x', 'yyy', 421cb0ef41Sopenharmony_ci 'X-req-Y', 'zzz; www', 431cb0ef41Sopenharmony_ci ]); 441cb0ef41Sopenharmony_ci assert.deepStrictEqual( 451cb0ef41Sopenharmony_ci req.trailers, { 'x-req-x': 'xxx, yyy', 'x-req-y': 'zzz; www' } 461cb0ef41Sopenharmony_ci ); 471cb0ef41Sopenharmony_ci assert.deepStrictEqual( 481cb0ef41Sopenharmony_ci req.trailersDistinct, 491cb0ef41Sopenharmony_ci { 'x-req-x': ['xxx', 'yyy'], 'x-req-y': ['zzz; www'] } 501cb0ef41Sopenharmony_ci ); 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci res.setHeader('X-Res-a', 'AAA'); 531cb0ef41Sopenharmony_ci res.appendHeader('x-res-a', ['BBB', 'CCC']); 541cb0ef41Sopenharmony_ci res.setHeader('X-Res-b', ['DDD', 'EEE']); 551cb0ef41Sopenharmony_ci res.appendHeader('x-res-b', ['FFF', 'GGG']); 561cb0ef41Sopenharmony_ci res.removeHeader('date'); 571cb0ef41Sopenharmony_ci res.writeHead(200, { 581cb0ef41Sopenharmony_ci 'Connection': 'close', 'x-res-c': ['HHH', 'III'], 591cb0ef41Sopenharmony_ci 'x-res-d': ['JJJ', 'KKK', 'LLL'] 601cb0ef41Sopenharmony_ci }); 611cb0ef41Sopenharmony_ci res.addTrailers({ 621cb0ef41Sopenharmony_ci 'x-res-x': ['XXX', 'YYY'], 631cb0ef41Sopenharmony_ci 'X-Res-Y': ['ZZZ', 'WWW'] 641cb0ef41Sopenharmony_ci }); 651cb0ef41Sopenharmony_ci res.write('BODY'); 661cb0ef41Sopenharmony_ci res.end(); 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ci assert.deepStrictEqual(res.getHeader('X-Res-a'), ['AAA', 'BBB', 'CCC']); 691cb0ef41Sopenharmony_ci assert.deepStrictEqual(res.getHeader('x-res-a'), ['AAA', 'BBB', 'CCC']); 701cb0ef41Sopenharmony_ci assert.deepStrictEqual( 711cb0ef41Sopenharmony_ci res.getHeader('x-res-b'), ['DDD', 'EEE', 'FFF', 'GGG'] 721cb0ef41Sopenharmony_ci ); 731cb0ef41Sopenharmony_ci assert.deepStrictEqual(res.getHeader('x-res-c'), ['HHH', 'III']); 741cb0ef41Sopenharmony_ci assert.strictEqual(res.getHeader('connection'), 'close'); 751cb0ef41Sopenharmony_ci assert.deepStrictEqual( 761cb0ef41Sopenharmony_ci res.getHeaderNames(), 771cb0ef41Sopenharmony_ci ['x-res-a', 'x-res-b', 'connection', 'x-res-c', 'x-res-d'] 781cb0ef41Sopenharmony_ci ); 791cb0ef41Sopenharmony_ci assert.deepStrictEqual( 801cb0ef41Sopenharmony_ci res.getRawHeaderNames(), 811cb0ef41Sopenharmony_ci ['X-Res-a', 'X-Res-b', 'Connection', 'x-res-c', 'x-res-d'] 821cb0ef41Sopenharmony_ci ); 831cb0ef41Sopenharmony_ci 841cb0ef41Sopenharmony_ci const headers = Object.create(null); 851cb0ef41Sopenharmony_ci Object.assign(headers, { 861cb0ef41Sopenharmony_ci 'x-res-a': [ 'AAA', 'BBB', 'CCC' ], 871cb0ef41Sopenharmony_ci 'x-res-b': [ 'DDD', 'EEE', 'FFF', 'GGG' ], 881cb0ef41Sopenharmony_ci 'connection': 'close', 891cb0ef41Sopenharmony_ci 'x-res-c': [ 'HHH', 'III' ], 901cb0ef41Sopenharmony_ci 'x-res-d': [ 'JJJ', 'KKK', 'LLL' ] 911cb0ef41Sopenharmony_ci }); 921cb0ef41Sopenharmony_ci assert.deepStrictEqual(res.getHeaders(), headers); 931cb0ef41Sopenharmony_ci }); 941cb0ef41Sopenharmony_ci 951cb0ef41Sopenharmony_ci req.resume(); 961cb0ef41Sopenharmony_ci } 971cb0ef41Sopenharmony_ci )); 981cb0ef41Sopenharmony_ci 991cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 1001cb0ef41Sopenharmony_ci const req = request({ 1011cb0ef41Sopenharmony_ci host: '127.0.0.1', 1021cb0ef41Sopenharmony_ci port: server.address().port, 1031cb0ef41Sopenharmony_ci path: '/', 1041cb0ef41Sopenharmony_ci method: 'POST', 1051cb0ef41Sopenharmony_ci headers: { 1061cb0ef41Sopenharmony_ci 'connection': 'close', 1071cb0ef41Sopenharmony_ci 'x-req-a': 'aaa', 1081cb0ef41Sopenharmony_ci 'X-Req-a': 'bbb', 1091cb0ef41Sopenharmony_ci 'X-Req-b': ['ccc', 'ddd'] 1101cb0ef41Sopenharmony_ci }, 1111cb0ef41Sopenharmony_ci uniqueHeaders: ['x-req-b', 'x-req-y'] 1121cb0ef41Sopenharmony_ci }, common.mustCall((res) => { 1131cb0ef41Sopenharmony_ci assert.deepStrictEqual(res.rawHeaders, [ 1141cb0ef41Sopenharmony_ci 'X-Res-a', 'AAA', 1151cb0ef41Sopenharmony_ci 'X-Res-a', 'BBB', 1161cb0ef41Sopenharmony_ci 'X-Res-a', 'CCC', 1171cb0ef41Sopenharmony_ci 'X-Res-b', 'DDD; EEE; FFF; GGG', 1181cb0ef41Sopenharmony_ci 'Connection', 'close', 1191cb0ef41Sopenharmony_ci 'x-res-c', 'HHH', 1201cb0ef41Sopenharmony_ci 'x-res-c', 'III', 1211cb0ef41Sopenharmony_ci 'x-res-d', 'JJJ; KKK; LLL', 1221cb0ef41Sopenharmony_ci 'Transfer-Encoding', 'chunked', 1231cb0ef41Sopenharmony_ci ]); 1241cb0ef41Sopenharmony_ci assert.deepStrictEqual(res.headers, { 1251cb0ef41Sopenharmony_ci 'x-res-a': 'AAA, BBB, CCC', 1261cb0ef41Sopenharmony_ci 'x-res-b': 'DDD; EEE; FFF; GGG', 1271cb0ef41Sopenharmony_ci 'connection': 'close', 1281cb0ef41Sopenharmony_ci 'x-res-c': 'HHH, III', 1291cb0ef41Sopenharmony_ci 'x-res-d': 'JJJ; KKK; LLL', 1301cb0ef41Sopenharmony_ci 'transfer-encoding': 'chunked' 1311cb0ef41Sopenharmony_ci }); 1321cb0ef41Sopenharmony_ci assert.deepStrictEqual(res.headersDistinct, { 1331cb0ef41Sopenharmony_ci 'x-res-a': [ 'AAA', 'BBB', 'CCC' ], 1341cb0ef41Sopenharmony_ci 'x-res-b': [ 'DDD; EEE; FFF; GGG' ], 1351cb0ef41Sopenharmony_ci 'connection': [ 'close' ], 1361cb0ef41Sopenharmony_ci 'x-res-c': [ 'HHH', 'III' ], 1371cb0ef41Sopenharmony_ci 'x-res-d': [ 'JJJ; KKK; LLL' ], 1381cb0ef41Sopenharmony_ci 'transfer-encoding': [ 'chunked' ] 1391cb0ef41Sopenharmony_ci }); 1401cb0ef41Sopenharmony_ci 1411cb0ef41Sopenharmony_ci res.on('end', function() { 1421cb0ef41Sopenharmony_ci assert.deepStrictEqual(res.rawTrailers, [ 1431cb0ef41Sopenharmony_ci 'x-res-x', 'XXX', 1441cb0ef41Sopenharmony_ci 'x-res-x', 'YYY', 1451cb0ef41Sopenharmony_ci 'X-Res-Y', 'ZZZ; WWW', 1461cb0ef41Sopenharmony_ci ]); 1471cb0ef41Sopenharmony_ci assert.deepStrictEqual( 1481cb0ef41Sopenharmony_ci res.trailers, 1491cb0ef41Sopenharmony_ci { 'x-res-x': 'XXX, YYY', 'x-res-y': 'ZZZ; WWW' } 1501cb0ef41Sopenharmony_ci ); 1511cb0ef41Sopenharmony_ci assert.deepStrictEqual( 1521cb0ef41Sopenharmony_ci res.trailersDistinct, 1531cb0ef41Sopenharmony_ci { 'x-res-x': ['XXX', 'YYY'], 'x-res-y': ['ZZZ; WWW'] } 1541cb0ef41Sopenharmony_ci ); 1551cb0ef41Sopenharmony_ci server.close(); 1561cb0ef41Sopenharmony_ci }); 1571cb0ef41Sopenharmony_ci res.resume(); 1581cb0ef41Sopenharmony_ci })); 1591cb0ef41Sopenharmony_ci 1601cb0ef41Sopenharmony_ci req.setHeader('X-Req-a', ['eee', 'fff']); 1611cb0ef41Sopenharmony_ci req.appendHeader('X-req-a', ['ggg', 'hhh']); 1621cb0ef41Sopenharmony_ci req.setHeader('X-Req-b', ['iii', 'jjj']); 1631cb0ef41Sopenharmony_ci req.appendHeader('x-req-b', ['kkk', 'lll']); 1641cb0ef41Sopenharmony_ci 1651cb0ef41Sopenharmony_ci req.addTrailers({ 1661cb0ef41Sopenharmony_ci 'x-req-x': ['xxx', 'yyy'], 1671cb0ef41Sopenharmony_ci 'X-req-Y': ['zzz', 'www'] 1681cb0ef41Sopenharmony_ci }); 1691cb0ef41Sopenharmony_ci 1701cb0ef41Sopenharmony_ci req.write('BODY'); 1711cb0ef41Sopenharmony_ci 1721cb0ef41Sopenharmony_ci req.end(); 1731cb0ef41Sopenharmony_ci})); 174