node/test/parallel/test-http2-util-assert-valid-pseudoheader.js
Tim Perry 0fccfa421b
http2: add strictSingleValueFields option to relax header validation
Previously it was impossible to send multiple values for any header
or trailer defined officially as supporting only a single value.

This is a good default, but in practice many of these headers are used
in weird & wonderful ways where this can be problematic. This new
option allows for relaxing this restriction to support those cases
where required.

This option defaults to true so validation will still be applied
as before, rejecting multiple single-value fields, unless explicitly
disabled.

PR-URL: https://github.com/nodejs/node/pull/59917
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2026-02-21 22:58:52 +00:00

20 lines
570 B
JavaScript

// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const { assertValidPseudoHeader } = require('internal/http2/util');
// These should not throw
assertValidPseudoHeader(':status');
assertValidPseudoHeader(':path');
assertValidPseudoHeader(':authority');
assertValidPseudoHeader(':scheme');
assertValidPseudoHeader(':method');
assert.throws(() => assertValidPseudoHeader(':foo'), {
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER',
name: 'TypeError',
message: '":foo" is an invalid pseudoheader or is used incorrectly'
});