11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciif (!common.hasCrypto) 51cb0ef41Sopenharmony_ci common.skip('missing crypto'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst h2 = require('http2'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci// Http2ServerRequest should have getter for trailers & rawTrailers 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst expectedTrailers = { 121cb0ef41Sopenharmony_ci 'x-foo': 'xOxOxOx, OxOxOxO, xOxOxOx, OxOxOxO', 131cb0ef41Sopenharmony_ci 'x-foo-test': 'test, test' 141cb0ef41Sopenharmony_ci}; 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciconst server = h2.createServer(); 171cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(function() { 181cb0ef41Sopenharmony_ci const port = server.address().port; 191cb0ef41Sopenharmony_ci server.once('request', common.mustCall(function(request, response) { 201cb0ef41Sopenharmony_ci let data = ''; 211cb0ef41Sopenharmony_ci request.setEncoding('utf8'); 221cb0ef41Sopenharmony_ci request.on('data', common.mustCallAtLeast((chunk) => data += chunk)); 231cb0ef41Sopenharmony_ci request.on('end', common.mustCall(() => { 241cb0ef41Sopenharmony_ci const trailers = request.trailers; 251cb0ef41Sopenharmony_ci for (const [name, value] of Object.entries(expectedTrailers)) { 261cb0ef41Sopenharmony_ci assert.strictEqual(trailers[name], value); 271cb0ef41Sopenharmony_ci } 281cb0ef41Sopenharmony_ci assert.deepStrictEqual([ 291cb0ef41Sopenharmony_ci 'x-foo', 301cb0ef41Sopenharmony_ci 'xOxOxOx', 311cb0ef41Sopenharmony_ci 'x-foo', 321cb0ef41Sopenharmony_ci 'OxOxOxO', 331cb0ef41Sopenharmony_ci 'x-foo', 341cb0ef41Sopenharmony_ci 'xOxOxOx', 351cb0ef41Sopenharmony_ci 'x-foo', 361cb0ef41Sopenharmony_ci 'OxOxOxO', 371cb0ef41Sopenharmony_ci 'x-foo-test', 381cb0ef41Sopenharmony_ci 'test, test', 391cb0ef41Sopenharmony_ci ], request.rawTrailers); 401cb0ef41Sopenharmony_ci assert.strictEqual(data, 'test\ntest'); 411cb0ef41Sopenharmony_ci response.end(); 421cb0ef41Sopenharmony_ci })); 431cb0ef41Sopenharmony_ci })); 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci const url = `http://localhost:${port}`; 461cb0ef41Sopenharmony_ci const client = h2.connect(url, common.mustCall(function() { 471cb0ef41Sopenharmony_ci const headers = { 481cb0ef41Sopenharmony_ci ':path': '/foobar', 491cb0ef41Sopenharmony_ci ':method': 'POST', 501cb0ef41Sopenharmony_ci ':scheme': 'http', 511cb0ef41Sopenharmony_ci ':authority': `localhost:${port}` 521cb0ef41Sopenharmony_ci }; 531cb0ef41Sopenharmony_ci const request = client.request(headers, { waitForTrailers: true }); 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_ci request.on('wantTrailers', () => { 561cb0ef41Sopenharmony_ci request.sendTrailers({ 571cb0ef41Sopenharmony_ci 'x-fOo': 'xOxOxOx', 581cb0ef41Sopenharmony_ci 'x-foO': 'OxOxOxO', 591cb0ef41Sopenharmony_ci 'X-fOo': 'xOxOxOx', 601cb0ef41Sopenharmony_ci 'X-foO': 'OxOxOxO', 611cb0ef41Sopenharmony_ci 'x-foo-test': 'test, test' 621cb0ef41Sopenharmony_ci }); 631cb0ef41Sopenharmony_ci }); 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci request.resume(); 661cb0ef41Sopenharmony_ci request.on('end', common.mustCall(function() { 671cb0ef41Sopenharmony_ci server.close(); 681cb0ef41Sopenharmony_ci client.close(); 691cb0ef41Sopenharmony_ci })); 701cb0ef41Sopenharmony_ci request.write('test\n'); 711cb0ef41Sopenharmony_ci request.end('test'); 721cb0ef41Sopenharmony_ci })); 731cb0ef41Sopenharmony_ci})); 74