Performs the low-level validations on the provided name that are done when res.setHeader(name, value) is called.
Passing illegal value as name will result in a TypeError being thrown,
identified by code: 'ERR_INVALID_HTTP_TOKEN'.
It is not necessary to use this method before passing headers to an HTTP request
or response. The HTTP module will automatically validate such headers.
Example:
import { validateHeaderName } from'node:http';
try { validateHeaderName(''); } catch (err) { console.error(errinstanceofTypeError); // --> true console.error(err.code); // --> 'ERR_INVALID_HTTP_TOKEN' console.error(err.message); // --> 'Header name must be a valid HTTP token [""]' }
Performs the low-level validations on the provided
name
that are done whenres.setHeader(name, value)
is called.Passing illegal value as
name
will result in aTypeError
being thrown, identified bycode: 'ERR_INVALID_HTTP_TOKEN'
.It is not necessary to use this method before passing headers to an HTTP request or response. The HTTP module will automatically validate such headers.
Example: