HTTP Header Validator is a lightweight, high-performance library for validating HTTP header keys and values as defined in RFC 7230, Section 3.2.6.
npm install http-header-validatorThis package is available for both ESM and CJS.
import { httpHeaderValidator } from "http-header-validator";const { httpHeaderValidator } = require("http-header-validator");const isValidKey = httpHeaderValidator.validateHeaderKey("Accept");
const isValidValue =
httpHeaderValidator.validateHeaderValue("application/json");
const isValidHeader = httpHeaderValidator.validateHeader(
"Accept",
"application/json"
);
console.log(isValidKey); // true
console.log(isValidValue); // true
console.log(isValidHeader); // trueValidates an HTTP header key.
- headerKey: The header key to validate.
- Returns:
trueif the header key is valid, otherwisefalse.
Validates an HTTP header value.
- headerValue: The header value to validate.
- Returns:
trueif the header value is valid, otherwisefalse.
Validates both an HTTP header key and value.
- headerKey: The header key to validate.
- headerValue: The header value to validate.
- Returns:
trueif both the header key and value are valid, otherwisefalse.