{"id":17320,"library":"parse-http-header","title":"HTTP Header Value Parameter Parser","description":"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.","status":"abandoned","version":"1.0.1","language":"javascript","source_language":"en","source_url":"git://github.com/danmactough/node-parse-http-header","tags":["javascript","http","parse","header","headers"],"install":[{"cmd":"npm install parse-http-header","lang":"bash","label":"npm"},{"cmd":"yarn add parse-http-header","lang":"bash","label":"yarn"},{"cmd":"pnpm add parse-http-header","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This library is CommonJS-only and does not provide an ESM export. Direct `import` statements will fail without a transpilation step or specific Node.js `--experimental-modules` configuration.","wrong":"import parseHttpHeader from 'parse-http-header';","symbol":"parseHttpHeader","correct":"const parseHttpHeader = require('parse-http-header');"},{"note":"The parser returns an array-like object where the primary header value is at index `0`, and parameters are accessible as named properties.","wrong":"const headerValue = parseHttpHeader('text/html; charset=UTF-8');\nconst mainType = headerValue.value; // Incorrect: main value is at index 0\nconst charset = headerValue['charset']; // Correct but less idiomatic for direct property access","symbol":"Parsing a value","correct":"const headerValue = parseHttpHeader('text/html; charset=UTF-8');\nconst mainType = headerValue[0]; // 'text/html'\nconst charset = headerValue.charset; // 'UTF-8'"}],"quickstart":{"code":"const parseHttpHeader = require('parse-http-header');\n\n// Simulate a response headers object\nconst responseHeaders = {\n  'content-type': 'text/html; charset=UTF-8',\n  'content-disposition': 'attachment; filename=\"report.pdf\"; size=12345'\n};\n\n// Parse Content-Type\nconst contentType = parseHttpHeader(responseHeaders['content-type']);\nconsole.log('Content-Type main value:', contentType[0]); // Output: text/html\nconsole.log('Content-Type charset:', contentType.charset); // Output: UTF-8\n\n// Parse Content-Disposition\nconst contentDisposition = parseHttpHeader(responseHeaders['content-disposition']);\nconsole.log('Content-Disposition main value:', contentDisposition[0]); // Output: attachment\nconsole.log('Content-Disposition filename:', contentDisposition.filename); // Output: report.pdf\nconsole.log('Content-Disposition size:', contentDisposition.size); // Output: 12345","lang":"javascript","description":"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."},"warnings":[{"fix":"Use `const parseHttpHeader = require('parse-http-header');` for module import.","message":"This package is CommonJS-only and does not provide an ESM export. Attempting to use `import` syntax will result in a runtime error or require complex transpilation/configuration in modern Node.js environments.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Always access the main value via `[0]` (e.g., `parsedHeader[0]`) and parameters via named properties (e.g., `parsedHeader.paramName`).","message":"The output format is an array-like object. The main header value is at index `0`, while parameters are properties. Misunderstanding this can lead to incorrect data access or `undefined` values.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For new projects or applications requiring robust and up-to-date HTTP header parsing, consider alternatives like `http-link-header` (for Link headers specifically), or more general-purpose HTTP parsing libraries that are actively maintained.","message":"This library appears to be unmaintained, with its latest copyright from 2014. It may not conform to newer HTTP header specifications (e.g., RFC 8941 Structured Headers) or handle all edge cases in modern HTTP parsing, potentially leading to incorrect or incomplete parsing results.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure that only the header's value string (the part after the colon) is passed to the `parseHttpHeader` function. If processing full header lines, pre-process them to extract only the value.","message":"The parser is designed for single header *value strings* (e.g., `text/html; charset=UTF-8`). It will not correctly parse entire HTTP header lines (which include the field name and colon) or multiple headers concatenated together, which can lead to unexpected output.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Change the import statement to `const parseHttpHeader = require('parse-http-header');`.","cause":"Attempting to import the CommonJS module using ESM `import` syntax without proper transpilation or Node.js module resolution configuration.","error":"TypeError: parseHttpHeader is not a function"},{"fix":"Ensure the input to `parseHttpHeader` is a valid string. Add a null/undefined check before accessing properties: `const parsed = parseHttpHeader(headerString); if (parsed) { console.log(parsed[0]); }`.","cause":"Attempting to access `[0]` on the result of `parseHttpHeader()` when the input was `null` or `undefined`, or the parsing failed to produce a valid array-like object.","error":"TypeError: Cannot read properties of undefined (reading '0')"},{"fix":"Verify the exact format of the header value. This library might have limitations with complex or non-standard parameter escaping. For advanced parsing, consider more robust HTTP header parsing libraries.","cause":"The input string might contain characters that the parser doesn't correctly handle as delimiters or escapes, especially within quoted strings. For instance, a semicolon inside a quoted filename might be misinterpreted as a new parameter.","error":"My header parameter 'foo' is missing or incorrect, even though it's in the string."}],"ecosystem":"npm","meta_description":null}