@achingbrain/http-parser-js

中文文档
0.5.9发布于 2025/04/10MITTypeScriptES Module近 30 天下载 4.8万

A pure JS HTTP parser

原始使用文档
文档目录5 节
  1. Testing
  2. Status
  3. Node versions
  4. Standalone usage
  5. License

This is a fork of http-parser-js without the dependency on node:buffer and converted to ESM

Node Node-v12

HTTP Parser

This library parses HTTP protocol for requests and responses. It was created to replace http_parser.c since calling C++ functions from JS is really slow in V8. However, it is now primarily useful in having a more flexible/tolerant HTTP parser when dealing with legacy services that do not meet the strict HTTP parsing rules Node's parser follows.

This is packaged as a standalone npm module. To use in node, monkeypatch HTTPParser.

// Monkey patch before you require http for the first time.
process.binding('http_parser').HTTPParser = require('http-parser-js').HTTPParser;

var http = require('http');
// ...

Testing

Simply run npm test. The tests are copied from node and mscedex/io.js, with some modifcations.

Status

This should now be usable in any node application, it now supports (nearly) everything http_parser.c does while still being tolerant with corrupted headers, and other kinds of malformed data.

Node versions

http-parser-js should work via monkey-patching on Node v6-v11, and v13-14.

Node v12.x renamed the internal http parser, and did not expose it for monkey-patching, so to be able to monkey-patch on Node v12, you must run node --http-parser=legacy file.js to opt in to the old, monkey-patchable http_parser binding.

Standalone usage

While this module is intended to be used as a replacement for the internal Node.js parser, it can be used as a standalone parser. The standalone-example.js demonstrates how to use the somewhat awkward API (coming from compatibility with the Node.js internals) to parse HTTP from raw Buffers.

License

MIT. See LICENSE.md

版本与发布记录

@achingbrain/http-parser-js 共发布 2 个版本,首次发布于 2025/03/26;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.5.9latest2025/04/101.6 年前
0.5.82025/03/261.6 年前

关于 @achingbrain/http-parser-js 的常见问题

@achingbrain/http-parser-js 是什么?

A pure JS HTTP parser

如何安装 @achingbrain/http-parser-js?

在项目目录运行 npm install @achingbrain/http-parser-js,或使用 pnpm add / yarn add / bun add。

@achingbrain/http-parser-js 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@achingbrain/http-parser-js 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@achingbrain/http-parser-js 可以商用吗?

@achingbrain/http-parser-js 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@achingbrain/http-parser-js 的下载量有多少?

根据 npm 官方下载统计,@achingbrain/http-parser-js 在 2026/10/05 – 2026/11/03 这 30 天内被下载 48,362 次,日均约 1,612 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@achingbrain/http-parser-js 还在维护吗?

最新版本 0.5.9 发布于 2025/04/10(1.6 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/03/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。