{"id":17251,"library":"hparser","title":"Low-level HTTP Parser for Whistle","description":"hparser is a low-level HTTP parser specifically designed to be used internally by the `whistle` network debugging and proxy tool. It provides capabilities to parse raw HTTP request and response data, handling the complexities of the HTTP protocol state machine. The package's current stable version is 0.5.0, with its last update approximately two years ago and it targets Node.js versions as old as `0.10.0` (released in 2013). This indicates a lack of active maintenance. Due to its specialized use-case within the `whistle` ecosystem and its abandoned status, it is not recommended for new projects or general-purpose HTTP parsing, especially given the availability of more modern and actively maintained alternatives.","status":"abandoned","version":"0.5.0","language":"javascript","source_language":"en","source_url":"https://github.com/avwo/hparser","tags":["javascript","whistle","http-parser"],"install":[{"cmd":"npm install hparser","lang":"bash","label":"npm"},{"cmd":"yarn add hparser","lang":"bash","label":"yarn"},{"cmd":"pnpm add hparser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"hparser is a CommonJS module, primarily exporting the `Parser` class. ES module `import` syntax is not supported.","wrong":"import { Parser } from 'hparser';","symbol":"Parser","correct":"const Parser = require('hparser');"},{"note":"The `execute` method is part of the `Parser` class prototype and is called on an instance to feed data chunks for parsing. The `Parser` itself is the default export.","wrong":"import { execute } from 'hparser';","symbol":"Parser.prototype.execute","correct":"const Parser = require('hparser');\nconst parser = new Parser();\nparser.execute(buffer);"},{"note":"Event handlers like `onHeadersComplete`, `onBody`, and `onMessageComplete` are properties of a `Parser` instance, not named exports. They are assigned functions for callback-based parsing.","wrong":"import { onHeadersComplete } from 'hparser';","symbol":"onHeadersComplete","correct":"const Parser = require('hparser');\nconst parser = new Parser();\nparser.onHeadersComplete = function() { /* ... */ };"}],"quickstart":{"code":"const Parser = require('hparser');\nconst { StringDecoder } = require('string_decoder');\n\nconst rawHttpRequest = Buffer.from(\n  'GET /index.html HTTP/1.1\\r\\n'\n  + 'Host: example.com\\r\\n'\n  + 'User-Agent: test-client\\r\\n'\n  + 'Accept: */*\\r\\n'\n  + '\\r\\n'\n);\n\nconst parser = new Parser();\nconst decoder = new StringDecoder('utf8');\n\nlet headers = {};\nlet bodyChunks = [];\n\nparser.onHeadersComplete = function() {\n  console.log('HTTP Version:', this.httpMajor + '.' + this.httpMinor);\n  console.log('Method:', this.method);\n  console.log('URL:', decoder.write(this.url));\n  for (let i = 0; i < this.headers.length; i += 2) {\n    const key = decoder.write(this.headers[i]);\n    const value = decoder.write(this.headers[i + 1]);\n    headers[key] = value;\n  }\n  console.log('Headers:', headers);\n};\n\nparser.onBody = function(buffer, start, len) {\n  bodyChunks.push(buffer.slice(start, start + len));\n};\n\nparser.onMessageComplete = function() {\n  console.log('Parsing complete!');\n  console.log('Body:', Buffer.concat(bodyChunks).toString());\n};\n\nparser.execute(rawHttpRequest);\nparser.finish();\n","lang":"javascript","description":"Demonstrates initializing the `Parser`, feeding it a raw HTTP request buffer, and using its callback events to extract HTTP version, method, URL, headers, and body."},"warnings":[{"fix":"Migrate to a modern, actively maintained HTTP parsing library like `http-parser-js` or utilize Node.js's built-in `http` module for higher-level parsing.","message":"The `hparser` package is effectively abandoned. Its last release (v0.5.0) was over two years ago and targets extremely old Node.js versions (>=0.10.0). It receives no security updates or bug fixes, making it unsuitable for production use.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Always use `const Parser = require('hparser');` for importing the module.","message":"hparser is a CommonJS-only module. Attempting to use ES module `import` syntax will result in a runtime error like `SyntaxError: Named export 'Parser' not found.`. It does not provide an ES module entry point.","severity":"gotcha","affected_versions":">=0.5.0"},{"fix":"Consider writing a `hparser.d.ts` file (e.g., `declare module 'hparser' { class Parser { /* ... */ } export = Parser; }`) or migrating to a library with built-in or community-maintained types.","message":"The library is low-level and does not come with official TypeScript type definitions. Developers using TypeScript will need to create their own declaration files (`.d.ts`) or use a generic `any` type for imports and usage, which reduces type safety.","severity":"gotcha","affected_versions":">=0.5.0"},{"fix":"Implement robust error handling, buffer management, and state tracking around the parser's `execute` and `finish` methods. Alternatively, use higher-level HTTP libraries if stream-level control is not strictly required.","message":"As a low-level parser, `hparser` requires manual handling of raw `Buffer` instances and managing parser state through event-like callbacks. It does not abstract away streaming complexities or provide high-level request/response objects directly, requiring more boilerplate code.","severity":"breaking","affected_versions":">=0.5.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 CommonJS `const Parser = require('hparser');`.","cause":"Attempting to use ES module `import { Parser } from 'hparser';` syntax with a CommonJS-only package.","error":"SyntaxError: Named export 'Parser' not found. The requested module 'hparser' does not provide an export named 'Parser'"},{"fix":"Ensure event handler functions are bound correctly to the parser instance, typically by using regular function declarations (`function() { ... }`) or explicitly assigning them as methods (`parser.onHeadersComplete = function() { ... }`) where `this` refers to the parser instance. Avoid arrow functions for these handlers unless explicitly binding their `this` context.","cause":"The parser's event handlers (`onHeadersComplete`, `onBody`, `onMessageComplete`, etc.) are properties of the parser instance (`this`) within the handler function's scope. This error typically occurs if a handler is defined as an arrow function or if the `this` context is lost when the callback is invoked.","error":"TypeError: Cannot read properties of undefined (reading 'onHeadersComplete')"}],"ecosystem":"npm","meta_description":null}