bare-http-parser is a streaming HTTP request and response parser specifically designed for the Bare JavaScript runtime. Bare is a lightweight, modular runtime optimized for desktop and mobile environments, emphasizing embedded and cross-device support, particularly for peer-to-peer applications. This library, currently at version 1.1.3, provides the foundational capability to interpret raw HTTP stream data efficiently within the Bare ecosystem. Unlike traditional HTTP parsers that might operate on complete buffered messages, bare-http-parser processes data as it arrives, making it suitable for low-latency network operations characteristic of peer-to-peer systems. Its release cadence aligns with the development of the broader Holepunch/Bare project, with updates typically coinciding with advancements in the runtime itself. This parser is a critical component for building HTTP-based networking features directly within Bare applications, leveraging its stream-first architecture.
npm install bare-http-parserVerified import paths — ran on the pinned version, not inferred.
This example demonstrates parsing a raw HTTP request and response using `HTTPRequestParser` and `HTTPResponseParser` classes, handling streaming data and event emission for headers, request/response lines, and body data.
Implement explicit timeout mechanisms and 'error' event listeners. Validate parsed content lengths against actual received body data. For `Content-Length` mismatches, consider the stream closed prematurely.
Prefer ESM `import` syntax. If encountering issues with `require()`, explicitly check the package's `exports` map in its `package.json` for correct paths and module types. Ensure your project's `tsconfig.json` (if using TypeScript) or build configuration is aligned with the target module system.
When processing headers, iterate over the raw headers array (e.g., `[['Header-Name', 'value1'], ['Header-Name', 'value2']]`) and store values in an array for multi-value headers, rather than overwriting them in a simple object. For example, `headers[name].push(value)`.
Ensure you are using named imports: `import { HTTPRequestParser } from 'bare-http-parser';` for ESM, or `const { HTTPRequestParser } = require('bare-http-parser');` for CommonJS.Implement comprehensive error handling on the parser's 'error' event and the underlying stream's 'close' or 'end' events. Consider adding timeouts to detect stalled connections. For client applications, retry logic might be necessary. For servers, send an appropriate HTTP error response.
No dependency data recorded yet.