HTTP Headers Parser

3.0.2 · abandoned · verified Tue Apr 21

The `http-headers` package provides a utility to parse HTTP request and response start-lines and headers into a structured JavaScript object. It can process raw string or Buffer data containing complete HTTP messages, or directly extract and parse headers from Node.js `http.ServerResponse` objects. Key features include automatic body detection and ignored parsing, RFC 2068 compliance, and support for multi-line and repeating headers. The current stable version is 3.0.2. This package appears to be unmaintained; its last update was several years ago, meaning it does not receive active development, bug fixes, or compatibility updates for newer Node.js versions or HTTP standards (e.g., HTTP/2, HTTP/3). Its primary differentiator was simplifying the extraction of response headers from Node's internal `_header` property, which was not easily accessible otherwise.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `http-headers` to parse and access the response headers directly from an `http.ServerResponse` object in a Node.js server, a key use case for this library.

const http = require('http');
const httpHeaders = require('http-headers');

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.setHeader('X-Request-ID', '12345');
  res.end('Hello World');

  // Log the parsed response headers as they were sent to the client
  // This uses http-headers to access the internal _header property of res
  console.log('Parsed ServerResponse headers:', httpHeaders(res));
}).listen(8080, () => {
  console.log('Server listening on http://localhost:8080');
});

// To test, run the server and access http://localhost:8080 in your browser or with curl.
// The server's console will output the parsed response headers.

view raw JSON →