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 http2 = require('http2');
81cb0ef41Sopenharmony_ciconst body =
91cb0ef41Sopenharmony_ci  '<html><head></head><body><h1>this is some data</h2></body></html>';
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst server = http2.createServer((req, res) => {
121cb0ef41Sopenharmony_ci  res.setHeader('foobar', 'baz');
131cb0ef41Sopenharmony_ci  res.setHeader('X-POWERED-BY', 'node-test');
141cb0ef41Sopenharmony_ci  res.setHeader('connection', 'connection-test');
151cb0ef41Sopenharmony_ci  res.end(body);
161cb0ef41Sopenharmony_ci});
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => {
191cb0ef41Sopenharmony_ci  const client = http2.connect(`http://localhost:${server.address().port}`);
201cb0ef41Sopenharmony_ci  const headers = { ':path': '/' };
211cb0ef41Sopenharmony_ci  const req = client.request(headers);
221cb0ef41Sopenharmony_ci  req.setEncoding('utf8');
231cb0ef41Sopenharmony_ci  req.on('response', common.mustCall(function(headers) {
241cb0ef41Sopenharmony_ci    assert.strictEqual(headers.foobar, 'baz');
251cb0ef41Sopenharmony_ci    assert.strictEqual(headers['x-powered-by'], 'node-test');
261cb0ef41Sopenharmony_ci  }));
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci  let data = '';
291cb0ef41Sopenharmony_ci  req.on('data', (d) => data += d);
301cb0ef41Sopenharmony_ci  req.on('end', () => {
311cb0ef41Sopenharmony_ci    assert.strictEqual(body, data);
321cb0ef41Sopenharmony_ci    server.close();
331cb0ef41Sopenharmony_ci    client.close();
341cb0ef41Sopenharmony_ci  });
351cb0ef41Sopenharmony_ci  req.end();
361cb0ef41Sopenharmony_ci}));
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ciconst compatMsg = 'The provided connection header is not valid, ' +
391cb0ef41Sopenharmony_ci                  'the value will be dropped from the header and ' +
401cb0ef41Sopenharmony_ci                  'will never be in use.';
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_cicommon.expectWarning('UnsupportedWarning', compatMsg);
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ciserver.on('error', common.mustNotCall());
45