Registry / http-networking / http-headers-validation

http-headers-validation

JSON →
library0.0.2jsnpmunverified

http-headers-validation is a lightweight JavaScript utility designed to validate HTTP header names and values against standard specifications. Currently at version 0.0.2, this package appears to have an infrequent release cadence given its early version and specific utility focus. Its primary differentiator is providing a simple, focused API for ensuring header compliance, which is particularly useful in backend modules or proxies that process user-provided HTTP headers. It offers three core functions: `validateHeaderName`, `validateHeaderValue`, and `validateHeader` (which combines both). The library ships with TypeScript types, supporting modern development workflows. It differentiates itself from more comprehensive HTTP parsing libraries by focusing solely on header syntax validation, rather than full request/response object manipulation.

npm install http-headers-validation
INSTALL
IMPORT
SIG · HTTP-HEADERS-VALID
H
http-headers-validation
http-networkingjavascriptv0.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

validateHeaderName
import { validateHeaderName } from 'http-headers-validation';
import validateHeaderName from 'http-headers-validation';
This is a named export. Ensure you destructure it correctly.
validateHeaderValue
import { validateHeaderValue } from 'http-headers-validation';
const { validateHeaderValue } = require('http-headers-validation');
While CJS `require` works, ESM `import` is preferred in modern Node.js and TypeScript projects. For browser usage via script tag, the global `headerUtils` object exposes this function.
validateHeader
import { validateHeader } from 'http-headers-validation';
const headerUtils = require('http-headers-validation'); headerUtils.validateHeaderName('...');
The package exports individual validation functions. While `headerUtils` works in CJS, direct named imports are idiomatic for ESM. In browsers, `headerUtils.validateHeader` is available globally.

This quickstart demonstrates how to import and use the `validateHeaderName`, `validateHeaderValue`, and `validateHeader` functions to check the conformance of HTTP header strings against the standard, including a practical usage example.

import { validateHeaderName, validateHeaderValue, validateHeader } from 'http-headers-validation'; // Validate a header name const isValidName1 = validateHeaderName('If-Unmodified-Since'); // true const isValidName2 = validateHeaderName('Front-End-[]'); // false console.log(`'If-Unmodified-Since' is valid: ${isValidName1}`); console.log(`'Front-End-[]' is valid: ${isValidName2}`); // Validate a header value const isValidValue1 = validateHeaderValue('VQcFUFFRCBABUFhaAwQOVw=='); // true const isValidValue2 = validateHeaderValue('\n\b'); // false console.log(`'VQcFUFFRC...' is valid: ${isValidValue1}`); console.log(`'\n\b' is valid: ${isValidValue2}`); // Validate both name and value combined const isValidHeader1 = validateHeader('Cache-Control', 'public, max-age=2000'); // true const isValidHeader2 = validateHeader('Front-End-[]', 'backspace\bValue'); // false console.log(`'Cache-Control: public, max-age=2000' is valid: ${isValidHeader1}`); console.log(`'Front-End-[]: backspace\bValue' is valid: ${isValidHeader2}`); // Example of how it might be used in a server middleware function processHeaders(headers: Record<string, string>) { for (const name in headers) { const value = headers[name]; if (!validateHeader(name, value)) { console.warn(`Invalid header detected: ${name}: ${value}`); // Potentially throw an error or sanitize } } } processHeaders({ 'Accept': 'application/json', 'Custom-Bad-Header[]': 'oops\tbad value' });
Debug
Known issues
gotchaThe package is currently at an early version (0.0.2). While functional, API stability may not be guaranteed, and future updates could introduce breaking changes without explicit major version bumps typical of more mature libraries.
fix
Pin exact versions (e.g., `"http-headers-validation": "0.0.2"`) in your `package.json` to prevent unexpected updates. Regularly review the GitHub repository for new releases and changes.
affects: <=0.0.2
gotchaThe README explicitly shows CommonJS `require` examples and mentions a global `headerUtils` for client-side script tags, but doesn't detail official ESM module entry points beyond what's implied by shipping TypeScript types. While modern bundlers handle CJS in ESM, direct ESM imports are preferred.
fix
For Node.js ESM or TypeScript projects, use named imports like `import { validateHeaderName } from 'http-headers-validation';`. If using in a browser via a script tag, ensure the `index.js` file is included and access functions via the global `headerUtils` object.
affects: <=0.0.2
gotchaThe utility validates header names and values based on 'the standart' as stated in the README, implying RFCs. However, the specific RFC (e.g., RFC 7230, RFC 9110) or any edge cases regarding internationalization (e.g., non-ASCII characters in values for specific headers) are not explicitly detailed.
fix
Consult the source code on GitHub for exact validation logic if specific RFC compliance or edge-case behavior is critical for your application. Consider adding internal integration tests for scenarios not explicitly covered by the library's tests.
affects: <=0.0.2
Errors
Common errors & fixes
TypeError: headerUtils.validateHeaderName is not a function
Attempting to use `headerUtils` global or CJS `require` object with ESM named imports, or incorrect destructuring.
fix
If using ESM, ensure you are using named imports: `import { validateHeaderName } from 'http-headers-validation';`. If in a browser with a script tag, ensure the `index.js` file is loaded and the `headerUtils` global is available before calling its methods.
Error: Cannot find module 'http-headers-validation'
The package has not been installed or is not correctly resolved in the module path.
fix
Run `npm install http-headers-validation` or `yarn add http-headers-validation` in your project directory. Check your `package.json` dependencies.
Argument of type 'null' is not assignable to parameter of type 'string'.
Passing `null`, `undefined`, or a non-string type to a validation function in a TypeScript project.
fix
Ensure all arguments passed to `validateHeaderName`, `validateHeaderValue`, or `validateHeader` are non-empty strings, as required by the function signatures and documented API.
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
http-headers-validation — npm install http-headers-validation · libregistry