11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciif (!common.hasCrypto) { common.skip('missing crypto'); }
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci// Check for:
61cb0ef41Sopenharmony_ci// Spaced headers
71cb0ef41Sopenharmony_ci// Pseudo headers
81cb0ef41Sopenharmony_ci// Capitalized headers
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst http2 = require('http2');
111cb0ef41Sopenharmony_ciconst { throws, strictEqual } = require('assert');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci{
141cb0ef41Sopenharmony_ci  const server = http2.createServer(common.mustCall((req, res) => {
151cb0ef41Sopenharmony_ci    throws(() => {
161cb0ef41Sopenharmony_ci      res.setHeader(':path', '/');
171cb0ef41Sopenharmony_ci    }, {
181cb0ef41Sopenharmony_ci      code: 'ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED'
191cb0ef41Sopenharmony_ci    });
201cb0ef41Sopenharmony_ci    throws(() => {
211cb0ef41Sopenharmony_ci      res.setHeader('t est', 123);
221cb0ef41Sopenharmony_ci    }, {
231cb0ef41Sopenharmony_ci      code: 'ERR_INVALID_HTTP_TOKEN'
241cb0ef41Sopenharmony_ci    });
251cb0ef41Sopenharmony_ci    res.setHeader('TEST', 123);
261cb0ef41Sopenharmony_ci    res.setHeader('test_', 123);
271cb0ef41Sopenharmony_ci    res.setHeader(' test', 123);
281cb0ef41Sopenharmony_ci    res.end();
291cb0ef41Sopenharmony_ci  }));
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(() => {
321cb0ef41Sopenharmony_ci    const session = http2.connect(`http://localhost:${server.address().port}`);
331cb0ef41Sopenharmony_ci    session.request({ 'test_': 123, 'TEST': 123 })
341cb0ef41Sopenharmony_ci      .on('end', common.mustCall(() => {
351cb0ef41Sopenharmony_ci        session.close();
361cb0ef41Sopenharmony_ci        server.close();
371cb0ef41Sopenharmony_ci      }));
381cb0ef41Sopenharmony_ci  }));
391cb0ef41Sopenharmony_ci}
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci{
421cb0ef41Sopenharmony_ci  const server = http2.createServer();
431cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(() => {
441cb0ef41Sopenharmony_ci    const session = http2.connect(`http://localhost:${server.address().port}`);
451cb0ef41Sopenharmony_ci    session.on('error', common.mustCall((e) => {
461cb0ef41Sopenharmony_ci      strictEqual(e.code, 'ERR_INVALID_HTTP_TOKEN');
471cb0ef41Sopenharmony_ci      server.close();
481cb0ef41Sopenharmony_ci    }));
491cb0ef41Sopenharmony_ci    throws(() => {
501cb0ef41Sopenharmony_ci      session.request({ 't est': 123 });
511cb0ef41Sopenharmony_ci    }, {
521cb0ef41Sopenharmony_ci      code: 'ERR_INVALID_HTTP_TOKEN'
531cb0ef41Sopenharmony_ci    });
541cb0ef41Sopenharmony_ci  }));
551cb0ef41Sopenharmony_ci}
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci{
591cb0ef41Sopenharmony_ci  const server = http2.createServer();
601cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(() => {
611cb0ef41Sopenharmony_ci    const session = http2.connect(`http://localhost:${server.address().port}`);
621cb0ef41Sopenharmony_ci    session.on('error', common.mustCall((e) => {
631cb0ef41Sopenharmony_ci      strictEqual(e.code, 'ERR_INVALID_HTTP_TOKEN');
641cb0ef41Sopenharmony_ci      server.close();
651cb0ef41Sopenharmony_ci    }));
661cb0ef41Sopenharmony_ci    throws(() => {
671cb0ef41Sopenharmony_ci      session.request({ ' test': 123 });
681cb0ef41Sopenharmony_ci    }, {
691cb0ef41Sopenharmony_ci      code: 'ERR_INVALID_HTTP_TOKEN'
701cb0ef41Sopenharmony_ci    });
711cb0ef41Sopenharmony_ci  }));
721cb0ef41Sopenharmony_ci}
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ci{
751cb0ef41Sopenharmony_ci  const server = http2.createServer();
761cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(() => {
771cb0ef41Sopenharmony_ci    const session4 = http2.connect(`http://localhost:${server.address().port}`);
781cb0ef41Sopenharmony_ci    throws(() => {
791cb0ef41Sopenharmony_ci      session4.request({ ':test': 123 });
801cb0ef41Sopenharmony_ci    }, {
811cb0ef41Sopenharmony_ci      code: 'ERR_HTTP2_INVALID_PSEUDOHEADER'
821cb0ef41Sopenharmony_ci    });
831cb0ef41Sopenharmony_ci    session4.close();
841cb0ef41Sopenharmony_ci    server.close();
851cb0ef41Sopenharmony_ci  }));
861cb0ef41Sopenharmony_ci}
87