@balena/proxy-protocol-parser

中文文档
1.0.3发布于 2026/03/02Apache-2.0TypeScript构建来源已验证近 30 天下载 3190

Encoder and Decoder for proxy protocol v1 text and v2 binary formats

原始使用文档
文档目录5 节
  1. Overview
  2. install
  3. encode
  4. decode
  5. test

proxy-protocol-parser

npm version dependencies

Overview

A simple encoder and decoder for proxy protocol headers using the v1 text and v2 binary formats.

See http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt for details.

Supports IPv4 and IPv6, UDP and TCP, but not UNIX sockets.

install

npm install @balena/proxy-protocol-parser

encode

Separate v1 and v2 encoders are provided.

var buf = require('@balena/proxy-protocol-parser').v2_encode(socket);

or

var buf = require('proxy-protocol-parser').v2_encode({
  remoteFamily: 'IPv4',
  remoteAddress: '12.34.56.78',
  remotePort: 1234,
  localAddress: '172.16.0.1,
  localPort: 8080,
  protocol: 'udp'
});

protocol defaults to 'tcp' if unspecified.

The v1_encode function has the same API but is constrained by the limits of the v1 format, so only the tcp protocol is supported.

decode

A generic decoder is provided that detects the format of any header. If no valid v1 or v2 signature is detected, null is returned.

var details = require('@balena/proxy-protocol-parser').decode(buf);
if(details === null) {
    console.log('No proxy protocol header detected');
}

var remoteFamily = details.remoteFamily,
    remoteAddress = details.remoteAddress,
    remotePort = details.remotePort,
    localAddress = details.localAddress,
    localPort = details.localPort,
    protocol = details.prototol;

Separate decoders are provided for each version if the expected version is known.

var v1_details = require('@balena/proxy-protocol-parser').v1_decode(buf);
var v2_details = require('@balena/proxy-protocol-parser').v2_decode(buf);

The format-specific functions will assume the presence of a header and may throw an Error or return invalid details if a header is not present.

Each decode operation takes an optional validate second argument which causes the header to be validated (with an Error being thrown if invalid) at the minor cost of checking the signature validity an other validity checks on field values.

test

nodeunit test

版本与发布记录

@balena/proxy-protocol-parser 共发布 19 个版本,首次发布于 2019/03/08;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.3latest2026/03/028 个月前
1.0.3-build-updates-c4f4bb356b142a554d6a92a44683a472eefb1775-1build-updates2026/03/028 个月前
1.0.3-build-updates-0e0472690b9728eaf9cde19bfed8260f7a30222a-12026/02/288 个月前
1.0.3-build-updates-e799db0715267bda3fa268683cedd344e188346b-12026/02/288 个月前
1.0.3-build-updates-4b6735421c669c5e494cc60161dec038cd945dc0-12026/02/278 个月前
1.0.22020/09/016 年前

关于 @balena/proxy-protocol-parser 的常见问题

@balena/proxy-protocol-parser 是什么?

Encoder and Decoder for proxy protocol v1 text and v2 binary formats

如何安装 @balena/proxy-protocol-parser?

在项目目录运行 npm install @balena/proxy-protocol-parser,或使用 pnpm add / yarn add / bun add。

@balena/proxy-protocol-parser 支持 TypeScript 吗?

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

@balena/proxy-protocol-parser 可以商用吗?

@balena/proxy-protocol-parser 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@balena/proxy-protocol-parser 的下载量有多少?

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

@balena/proxy-protocol-parser 还在维护吗?

最新版本 1.0.3 发布于 2026/03/02(8 个月前);至今共发布 19 个版本,其中过去 12 个月发布了 5 个;首次发布于 2019/03/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。