11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciif (!common.hasCrypto)
41cb0ef41Sopenharmony_ci  common.skip('missing crypto');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ciconst http2 = require('http2');
71cb0ef41Sopenharmony_ciconst makeDuplexPair = require('../common/duplexpair');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci{
101cb0ef41Sopenharmony_ci  const testData = '<h1>Hello World</h1>';
111cb0ef41Sopenharmony_ci  const server = http2.createServer();
121cb0ef41Sopenharmony_ci  server.on('stream', common.mustCall((stream, headers) => {
131cb0ef41Sopenharmony_ci    stream.respond({
141cb0ef41Sopenharmony_ci      'content-type': 'text/html',
151cb0ef41Sopenharmony_ci      ':status': 200,
161cb0ef41Sopenharmony_ci      'cookie': 'donotindex',
171cb0ef41Sopenharmony_ci      'not-sensitive': 'foo',
181cb0ef41Sopenharmony_ci      'sensitive': 'bar',
191cb0ef41Sopenharmony_ci      // sensitiveHeaders entries are case-insensitive
201cb0ef41Sopenharmony_ci      [http2.sensitiveHeaders]: ['Sensitive']
211cb0ef41Sopenharmony_ci    });
221cb0ef41Sopenharmony_ci    stream.end(testData);
231cb0ef41Sopenharmony_ci  }));
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci  const { clientSide, serverSide } = makeDuplexPair();
261cb0ef41Sopenharmony_ci  server.emit('connection', serverSide);
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci  const client = http2.connect('http://localhost:80', {
291cb0ef41Sopenharmony_ci    createConnection: common.mustCall(() => clientSide)
301cb0ef41Sopenharmony_ci  });
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci  const req = client.request({ ':path': '/' });
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci  req.on('response', common.mustCall((headers) => {
351cb0ef41Sopenharmony_ci    assert.strictEqual(headers[':status'], 200);
361cb0ef41Sopenharmony_ci    assert.strictEqual(headers.cookie, 'donotindex');
371cb0ef41Sopenharmony_ci    assert.deepStrictEqual(headers[http2.sensitiveHeaders],
381cb0ef41Sopenharmony_ci                           ['cookie', 'sensitive']);
391cb0ef41Sopenharmony_ci  }));
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci  req.on('end', common.mustCall(() => {
421cb0ef41Sopenharmony_ci    clientSide.destroy();
431cb0ef41Sopenharmony_ci    clientSide.end();
441cb0ef41Sopenharmony_ci  }));
451cb0ef41Sopenharmony_ci  req.resume();
461cb0ef41Sopenharmony_ci  req.end();
471cb0ef41Sopenharmony_ci}
48