Skip to main content
validateHeaderName - node__http.d.ts - Node documentation
function validateHeaderName

Usage in Deno

```typescript import { validateHeaderName } from "node:node__http.d.ts"; ```
validateHeaderName(name: string): void
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: ```js import { validateHeaderName } from 'node:http'; try { validateHeaderName(''); } catch (err) { console.error(err instanceof TypeError); // --> true console.error(err.code); // --> 'ERR_INVALID_HTTP_TOKEN' console.error(err.message); // --> 'Header name must be a valid HTTP token [""]' } ```

Parameters

name: string

Return Type

void