11cb0ef41Sopenharmony_ci// Copyright Joyent, Inc. and other Node contributors.
21cb0ef41Sopenharmony_ci//
31cb0ef41Sopenharmony_ci// Permission is hereby granted, free of charge, to any person obtaining a
41cb0ef41Sopenharmony_ci// copy of this software and associated documentation files (the
51cb0ef41Sopenharmony_ci// "Software"), to deal in the Software without restriction, including
61cb0ef41Sopenharmony_ci// without limitation the rights to use, copy, modify, merge, publish,
71cb0ef41Sopenharmony_ci// distribute, sublicense, and/or sell copies of the Software, and to permit
81cb0ef41Sopenharmony_ci// persons to whom the Software is furnished to do so, subject to the
91cb0ef41Sopenharmony_ci// following conditions:
101cb0ef41Sopenharmony_ci//
111cb0ef41Sopenharmony_ci// The above copyright notice and this permission notice shall be included
121cb0ef41Sopenharmony_ci// in all copies or substantial portions of the Software.
131cb0ef41Sopenharmony_ci//
141cb0ef41Sopenharmony_ci// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
151cb0ef41Sopenharmony_ci// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
161cb0ef41Sopenharmony_ci// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
171cb0ef41Sopenharmony_ci// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
181cb0ef41Sopenharmony_ci// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
191cb0ef41Sopenharmony_ci// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
201cb0ef41Sopenharmony_ci// USE OR OTHER DEALINGS IN THE SOFTWARE.
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci'use strict';
231cb0ef41Sopenharmony_cirequire('../common');
241cb0ef41Sopenharmony_ciconst assert = require('assert');
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ciconst http = require('http');
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_cihttp.createServer(function(req, res) {
291cb0ef41Sopenharmony_ci  const expectRawHeaders = [
301cb0ef41Sopenharmony_ci    'Host',
311cb0ef41Sopenharmony_ci    `localhost:${this.address().port}`,
321cb0ef41Sopenharmony_ci    'transfer-ENCODING',
331cb0ef41Sopenharmony_ci    'CHUNKED',
341cb0ef41Sopenharmony_ci    'x-BaR',
351cb0ef41Sopenharmony_ci    'yoyoyo',
361cb0ef41Sopenharmony_ci    'Connection',
371cb0ef41Sopenharmony_ci    'close',
381cb0ef41Sopenharmony_ci  ];
391cb0ef41Sopenharmony_ci  const expectHeaders = {
401cb0ef41Sopenharmony_ci    'host': `localhost:${this.address().port}`,
411cb0ef41Sopenharmony_ci    'transfer-encoding': 'CHUNKED',
421cb0ef41Sopenharmony_ci    'x-bar': 'yoyoyo',
431cb0ef41Sopenharmony_ci    'connection': 'close'
441cb0ef41Sopenharmony_ci  };
451cb0ef41Sopenharmony_ci  const expectRawTrailers = [
461cb0ef41Sopenharmony_ci    'x-bAr',
471cb0ef41Sopenharmony_ci    'yOyOyOy',
481cb0ef41Sopenharmony_ci    'x-baR',
491cb0ef41Sopenharmony_ci    'OyOyOyO',
501cb0ef41Sopenharmony_ci    'X-bAr',
511cb0ef41Sopenharmony_ci    'yOyOyOy',
521cb0ef41Sopenharmony_ci    'X-baR',
531cb0ef41Sopenharmony_ci    'OyOyOyO',
541cb0ef41Sopenharmony_ci  ];
551cb0ef41Sopenharmony_ci  const expectTrailers = { 'x-bar': 'yOyOyOy, OyOyOyO, yOyOyOy, OyOyOyO' };
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci  this.close();
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci  assert.deepStrictEqual(req.rawHeaders, expectRawHeaders);
601cb0ef41Sopenharmony_ci  assert.deepStrictEqual(req.headers, expectHeaders);
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ci  req.on('end', function() {
631cb0ef41Sopenharmony_ci    assert.deepStrictEqual(req.rawTrailers, expectRawTrailers);
641cb0ef41Sopenharmony_ci    assert.deepStrictEqual(req.trailers, expectTrailers);
651cb0ef41Sopenharmony_ci  });
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ci  req.resume();
681cb0ef41Sopenharmony_ci  res.setHeader('Trailer', 'x-foo');
691cb0ef41Sopenharmony_ci  res.addTrailers([
701cb0ef41Sopenharmony_ci    ['x-fOo', 'xOxOxOx'],
711cb0ef41Sopenharmony_ci    ['x-foO', 'OxOxOxO'],
721cb0ef41Sopenharmony_ci    ['X-fOo', 'xOxOxOx'],
731cb0ef41Sopenharmony_ci    ['X-foO', 'OxOxOxO'],
741cb0ef41Sopenharmony_ci  ]);
751cb0ef41Sopenharmony_ci  res.end('x f o o');
761cb0ef41Sopenharmony_ci}).listen(0, function() {
771cb0ef41Sopenharmony_ci  const req = http.request({ port: this.address().port, path: '/' });
781cb0ef41Sopenharmony_ci  req.addTrailers([
791cb0ef41Sopenharmony_ci    ['x-bAr', 'yOyOyOy'],
801cb0ef41Sopenharmony_ci    ['x-baR', 'OyOyOyO'],
811cb0ef41Sopenharmony_ci    ['X-bAr', 'yOyOyOy'],
821cb0ef41Sopenharmony_ci    ['X-baR', 'OyOyOyO'],
831cb0ef41Sopenharmony_ci  ]);
841cb0ef41Sopenharmony_ci  req.setHeader('transfer-ENCODING', 'CHUNKED');
851cb0ef41Sopenharmony_ci  req.setHeader('x-BaR', 'yoyoyo');
861cb0ef41Sopenharmony_ci  req.end('y b a r');
871cb0ef41Sopenharmony_ci  req.on('response', function(res) {
881cb0ef41Sopenharmony_ci    const expectRawHeaders = [
891cb0ef41Sopenharmony_ci      'Trailer',
901cb0ef41Sopenharmony_ci      'x-foo',
911cb0ef41Sopenharmony_ci      'Date',
921cb0ef41Sopenharmony_ci      null,
931cb0ef41Sopenharmony_ci      'Connection',
941cb0ef41Sopenharmony_ci      'close',
951cb0ef41Sopenharmony_ci      'Transfer-Encoding',
961cb0ef41Sopenharmony_ci      'chunked',
971cb0ef41Sopenharmony_ci    ];
981cb0ef41Sopenharmony_ci    const expectHeaders = {
991cb0ef41Sopenharmony_ci      'trailer': 'x-foo',
1001cb0ef41Sopenharmony_ci      'date': null,
1011cb0ef41Sopenharmony_ci      'connection': 'close',
1021cb0ef41Sopenharmony_ci      'transfer-encoding': 'chunked'
1031cb0ef41Sopenharmony_ci    };
1041cb0ef41Sopenharmony_ci    res.rawHeaders[3] = null;
1051cb0ef41Sopenharmony_ci    res.headers.date = null;
1061cb0ef41Sopenharmony_ci    assert.deepStrictEqual(res.rawHeaders, expectRawHeaders);
1071cb0ef41Sopenharmony_ci    assert.deepStrictEqual(res.headers, expectHeaders);
1081cb0ef41Sopenharmony_ci    res.on('end', function() {
1091cb0ef41Sopenharmony_ci      const expectRawTrailers = [
1101cb0ef41Sopenharmony_ci        'x-fOo',
1111cb0ef41Sopenharmony_ci        'xOxOxOx',
1121cb0ef41Sopenharmony_ci        'x-foO',
1131cb0ef41Sopenharmony_ci        'OxOxOxO',
1141cb0ef41Sopenharmony_ci        'X-fOo',
1151cb0ef41Sopenharmony_ci        'xOxOxOx',
1161cb0ef41Sopenharmony_ci        'X-foO',
1171cb0ef41Sopenharmony_ci        'OxOxOxO',
1181cb0ef41Sopenharmony_ci      ];
1191cb0ef41Sopenharmony_ci      const expectTrailers = { 'x-foo': 'xOxOxOx, OxOxOxO, xOxOxOx, OxOxOxO' };
1201cb0ef41Sopenharmony_ci
1211cb0ef41Sopenharmony_ci      assert.deepStrictEqual(res.rawTrailers, expectRawTrailers);
1221cb0ef41Sopenharmony_ci      assert.deepStrictEqual(res.trailers, expectTrailers);
1231cb0ef41Sopenharmony_ci      console.log('ok');
1241cb0ef41Sopenharmony_ci    });
1251cb0ef41Sopenharmony_ci    res.resume();
1261cb0ef41Sopenharmony_ci  });
1271cb0ef41Sopenharmony_ci});
128