nodejs/test/parallel/test-http2-util-assert-valid-pseudoheader.js
Tim Perry 4cd8e1914a http2: add raw header array support to h2Session.request()
This also notably changes error handling for request(). Previously some
invalid header values (but not all) would cause the session to be
unnecessarily destroyed automatically, e.g. passing an unparseable
header name to request(). This is no longer the case: header validation
failures will throw an error, but will not destroy the session or emit
'error' events.

PR-URL: https://github.com/nodejs/node/pull/57917
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2025-04-26 09:27:27 -07:00

25 lines
789 B
JavaScript

// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
// Tests the assertValidPseudoHeader function that is used within the
// buildNgHeaderString function. The assert function is not exported so we
// have to test it through buildNgHeaderString
const { buildNgHeaderString } = require('internal/http2/util');
// These should not throw
buildNgHeaderString({ ':status': 'a' });
buildNgHeaderString({ ':path': 'a' });
buildNgHeaderString({ ':authority': 'a' });
buildNgHeaderString({ ':scheme': 'a' });
buildNgHeaderString({ ':method': 'a' });
assert.throws(() => buildNgHeaderString({ ':foo': 'a' }), {
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER',
name: 'TypeError',
message: '":foo" is an invalid pseudoheader or is used incorrectly'
});