HTTP Header Value Parameter Parser

1.0.1 · abandoned · verified Wed Apr 22

The `parse-http-header` package (version 1.0.1) is a lightweight JavaScript utility specifically designed to extract structured information from parameterized HTTP header *value strings*. For instance, a common header value like `text/html; charset=UTF-8` is parsed into an object where `text/html` is accessible as the first element of an array, and parameters like `charset` are exposed as direct properties of that object. This allows developers to easily access both the primary media type and its associated attributes in a unified structure. Originally published around 2014, the library appears to be stable but has not seen active development or new releases in many years. Its key differentiators include its focused scope on parsing *just* the value string portion of a header, rather than handling full HTTP messages or multiple header lines, and its minimal footprint with no external runtime dependencies. It exclusively uses CommonJS module syntax.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to parse common parameterized HTTP header value strings like Content-Type and Content-Disposition, showing access to both the primary value and its parameters.

const parseHttpHeader = require('parse-http-header');

// Simulate a response headers object
const responseHeaders = {
  'content-type': 'text/html; charset=UTF-8',
  'content-disposition': 'attachment; filename="report.pdf"; size=12345'
};

// Parse Content-Type
const contentType = parseHttpHeader(responseHeaders['content-type']);
console.log('Content-Type main value:', contentType[0]); // Output: text/html
console.log('Content-Type charset:', contentType.charset); // Output: UTF-8

// Parse Content-Disposition
const contentDisposition = parseHttpHeader(responseHeaders['content-disposition']);
console.log('Content-Disposition main value:', contentDisposition[0]); // Output: attachment
console.log('Content-Disposition filename:', contentDisposition.filename); // Output: report.pdf
console.log('Content-Disposition size:', contentDisposition.size); // Output: 12345

view raw JSON →