Registry / devops / consume-http-header

consume-http-header

JSON →
library1.0.0jsnpmunverified

Consume an HTTP request or response stream until all headers have been read, leaving the stream ready to consume the body from the start. Version 1.0.0 is stable with a simple callback-based API. It parses headers from a TCP stream (e.g., net.Socket) and returns the parsed headers object. Lightweight, no dependencies, and focused solely on header consumption without handling chunked transfer encoding or body parsing. Alternatives like `http-parser-js` provide more complete parsing but are heavier.

npm install consume-http-header
INSTALL
IMPORT
SIG · CONSUME-HTTP-HEADE
C
consume-http-header
devopsjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

consume-http-header
const consume = require('consume-http-header')
import consume from 'consume-http-header'
The package does not provide ES module exports; use CommonJS require().
consume-http-header
const consume = require('consume-http-header')
const { consume } = require('consume-http-header')
The module exports a single function directly, not as a named export.
consume-http-header
const consume = require('consume-http-header')
const consume = require('consume-http-header').default
No default export; the function is the module.exports.

Connects to example.com, sends an HTTP GET request, consumes the response headers, and pipes the body to stdout.

const net = require('net'); const consume = require('consume-http-header'); const socket = net.connect({ host: 'example.com', port: 80 }); socket.write('GET / HTTP/1.1\r\n'); socket.write('Host: example.com\r\n'); socket.write('\r\n'); consume(socket, (err, req) => { if (err) throw err; console.log('Status:', req.statusCode); console.log('Headers:', req.headers); socket.pipe(process.stdout); });
Debug
Known issues
gotchaThe stream must be a TCP socket (net.Socket) or similar raw stream – not an HTTP IncomingMessage. Do not pass an already-parsed stream.
fix
Ensure the stream is a raw TCP connection before any HTTP parsing.
affects: >1.0.0
gotchaIf the stream ends before headers are fully parsed, the callback is called with an error. Handle this gracefully.
fix
Check for err in the callback and handle stream end properly.
affects: >1.0.0
gotchaThe callback returns parsed headers but does not handle Transfer-Encoding: chunked. The body may be chunked and must be decoded separately.
fix
After consuming headers, handle chunked body manually or use a module like 'chunked-transfer'.
affects: >1.0.0
Errors
Common errors & fixes
TypeError: consume is not a function
Importing using ES module syntax (import) instead of require().
fix
Use const consume = require('consume-http-header')
Error: stream ended without finding a complete HTTP header
The TCP connection closed before all headers arrived.
fix
Ensure the server sends complete headers; check network connectivity.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
consume-http-header — npm install consume-http-header · libregistry