{"id":16384,"library":"http-headers-validation","title":"HTTP Header Validation Utility","description":"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.","status":"active","version":"0.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/SVasilev/http-headers-validation","tags":["javascript","http","headers","header","validation","typescript"],"install":[{"cmd":"npm install http-headers-validation","lang":"bash","label":"npm"},{"cmd":"yarn add http-headers-validation","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-headers-validation","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This is a named export. Ensure you destructure it correctly.","wrong":"import validateHeaderName from 'http-headers-validation';","symbol":"validateHeaderName","correct":"import { validateHeaderName } from 'http-headers-validation';"},{"note":"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.","wrong":"const { validateHeaderValue } = require('http-headers-validation');","symbol":"validateHeaderValue","correct":"import { validateHeaderValue } from 'http-headers-validation';"},{"note":"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.","wrong":"const headerUtils = require('http-headers-validation');\nheaderUtils.validateHeaderName('...');","symbol":"validateHeader","correct":"import { validateHeader } from 'http-headers-validation';"}],"quickstart":{"code":"import { validateHeaderName, validateHeaderValue, validateHeader } from 'http-headers-validation';\n\n// Validate a header name\nconst isValidName1 = validateHeaderName('If-Unmodified-Since'); // true\nconst isValidName2 = validateHeaderName('Front-End-[]');      // false\nconsole.log(`'If-Unmodified-Since' is valid: ${isValidName1}`);\nconsole.log(`'Front-End-[]' is valid: ${isValidName2}`);\n\n// Validate a header value\nconst isValidValue1 = validateHeaderValue('VQcFUFFRCBABUFhaAwQOVw=='); // true\nconst isValidValue2 = validateHeaderValue('\\n\\b');                 // false\nconsole.log(`'VQcFUFFRC...' is valid: ${isValidValue1}`);\nconsole.log(`'\\n\\b' is valid: ${isValidValue2}`);\n\n// Validate both name and value combined\nconst isValidHeader1 = validateHeader('Cache-Control', 'public, max-age=2000'); // true\nconst isValidHeader2 = validateHeader('Front-End-[]', 'backspace\\bValue');     // false\nconsole.log(`'Cache-Control: public, max-age=2000' is valid: ${isValidHeader1}`);\nconsole.log(`'Front-End-[]: backspace\\bValue' is valid: ${isValidHeader2}`);\n\n// Example of how it might be used in a server middleware\nfunction processHeaders(headers: Record<string, string>) {\n  for (const name in headers) {\n    const value = headers[name];\n    if (!validateHeader(name, value)) {\n      console.warn(`Invalid header detected: ${name}: ${value}`);\n      // Potentially throw an error or sanitize\n    }\n  }\n}\n\nprocessHeaders({\n  'Accept': 'application/json',\n  'Custom-Bad-Header[]': 'oops\\tbad value'\n});","lang":"typescript","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"gotcha","affected_versions":"<=0.0.2"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"<=0.0.2"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"<=0.0.2"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"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.","cause":"Attempting to use `headerUtils` global or CJS `require` object with ESM named imports, or incorrect destructuring.","error":"TypeError: headerUtils.validateHeaderName is not a function"},{"fix":"Run `npm install http-headers-validation` or `yarn add http-headers-validation` in your project directory. Check your `package.json` dependencies.","cause":"The package has not been installed or is not correctly resolved in the module path.","error":"Error: Cannot find module 'http-headers-validation'"},{"fix":"Ensure all arguments passed to `validateHeaderName`, `validateHeaderValue`, or `validateHeader` are non-empty strings, as required by the function signatures and documented API.","cause":"Passing `null`, `undefined`, or a non-string type to a validation function in a TypeScript project.","error":"Argument of type 'null' is not assignable to parameter of type 'string'."}],"ecosystem":"npm"}