{"id":40750,"library":"consume-http-header","title":"consume-http-header","description":"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.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/watson/consume-http-header","tags":["javascript","http","header","headers","stream","socket","tcp","parse","parser"],"install":[{"cmd":"npm install consume-http-header","lang":"bash","label":"npm"},{"cmd":"yarn add consume-http-header","lang":"bash","label":"yarn"},{"cmd":"pnpm add consume-http-header","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package does not provide ES module exports; use CommonJS require().","wrong":"import consume from 'consume-http-header'","symbol":"consume-http-header","correct":"const consume = require('consume-http-header')"},{"note":"The module exports a single function directly, not as a named export.","wrong":"const { consume } = require('consume-http-header')","symbol":"consume-http-header","correct":"const consume = require('consume-http-header')"},{"note":"No default export; the function is the module.exports.","wrong":"const consume = require('consume-http-header').default","symbol":"consume-http-header","correct":"const consume = require('consume-http-header')"}],"quickstart":{"code":"const net = require('net');\nconst consume = require('consume-http-header');\n\nconst socket = net.connect({ host: 'example.com', port: 80 });\nsocket.write('GET / HTTP/1.1\\r\\n');\nsocket.write('Host: example.com\\r\\n');\nsocket.write('\\r\\n');\n\nconsume(socket, (err, req) => {\n  if (err) throw err;\n  console.log('Status:', req.statusCode);\n  console.log('Headers:', req.headers);\n  socket.pipe(process.stdout);\n});","lang":"javascript","description":"Connects to example.com, sends an HTTP GET request, consumes the response headers, and pipes the body to stdout."},"warnings":[{"fix":"Ensure the stream is a raw TCP connection before any HTTP parsing.","message":"The stream must be a TCP socket (net.Socket) or similar raw stream – not an HTTP IncomingMessage. Do not pass an already-parsed stream.","severity":"gotcha","affected_versions":">1.0.0"},{"fix":"Check for err in the callback and handle stream end properly.","message":"If the stream ends before headers are fully parsed, the callback is called with an error. Handle this gracefully.","severity":"gotcha","affected_versions":">1.0.0"},{"fix":"After consuming headers, handle chunked body manually or use a module like 'chunked-transfer'.","message":"The callback returns parsed headers but does not handle Transfer-Encoding: chunked. The body may be chunked and must be decoded separately.","severity":"gotcha","affected_versions":">1.0.0"}],"env_vars":null,"search_vec":"'1.0.0':30 'altern':72 'api':39 'base':38 'bodi':25,70 'callback':37 'callback-bas':36 'chunk':66 'complet':80 'consum':2,5,23 'consume-http-head':1 'consumpt':63 'depend':57 'e.g':47 'encod':68 'focus':59 'handl':65 'header':4,14,42,53,62,87,88 'heavier':84 'http':3,7,75,86 'http-parser-j':74 'javascript':85 'js':77 'leav':18 'lightweight':55 'like':73 'net.socket':48 'object':54 'pars':41,52,71,81,92 'parser':76,93 'provid':78 'read':17 'readi':21 'request':8 'respons':10 'return':50 'simpl':35 'socket':90 'sole':60 'stabl':32 'start':28 'stream':11,20,46,89 'tcp':45,91 'transfer':67 'version':29 'without':64","created_at":"2026-06-04T18:49:04.952242+00:00","updated_at":"2026-06-04T18:49:04.952242+00:00","problems":[{"fix":"Use const consume = require('consume-http-header')","cause":"Importing using ES module syntax (import) instead of require().","error":"TypeError: consume is not a function"},{"fix":"Ensure the server sends complete headers; check network connectivity.","cause":"The TCP connection closed before all headers arrived.","error":"Error: stream ended without finding a complete HTTP header"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/watson/consume-http-header#readme","github":"https://github.com/watson/consume-http-header","docs":null,"changelog":null,"pypi":null,"npm":"consume-http-header","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}