{"id":16304756,"url":"https://github.com/moznion/proxy-protocol-js","last_synced_at":"2025-09-11T21:33:57.064Z","repository":{"id":34637432,"uuid":"181197585","full_name":"moznion/proxy-protocol-js","owner":"moznion","description":"A PROXY protocol (v1/v2) builder and parser for JavaScript","archived":false,"fork":false,"pushed_at":"2023-03-04T03:34:46.000Z","size":1188,"stargazers_count":15,"open_issues_count":13,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-30T04:05:13.030Z","etag":null,"topics":["nodejs","proxy-protocol"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/proxy-protocol-js","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moznion.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-13T16:18:03.000Z","updated_at":"2025-02-11T15:50:55.000Z","dependencies_parsed_at":"2024-06-18T18:46:42.531Z","dependency_job_id":null,"html_url":"https://github.com/moznion/proxy-protocol-js","commit_stats":{"total_commits":202,"total_committers":4,"mean_commits":50.5,"dds":"0.49504950495049505","last_synced_commit":"25261bbc1678425baee088f68192b908acb51d24"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/moznion/proxy-protocol-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Fproxy-protocol-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Fproxy-protocol-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Fproxy-protocol-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Fproxy-protocol-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moznion","download_url":"https://codeload.github.com/moznion/proxy-protocol-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Fproxy-protocol-js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267652422,"owners_count":24122092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nodejs","proxy-protocol"],"created_at":"2024-10-10T21:04:43.453Z","updated_at":"2025-07-29T08:04:55.128Z","avatar_url":"https://github.com/moznion.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"proxy-protocol-js [![CircleCI](https://circleci.com/gh/moznion/proxy-protocol-js.svg?style=svg)](https://circleci.com/gh/moznion/proxy-protocol-js) [![codecov](https://codecov.io/gh/moznion/proxy-protocol-js/branch/master/graph/badge.svg)](https://codecov.io/gh/moznion/proxy-protocol-js) [![NPM](https://nodei.co/npm/proxy-protocol-js.png?compact=true)](https://nodei.co/npm/proxy-protocol-js/)\n==\n\nA [PROXY protocol](http://www.haproxy.org/download/1.8/doc/proxy-protocol.txt) builder and parser for JavaScript.\n\nFeatures\n--\n\n- Supports the features\n  - building PROXY protocol payload\n  - parsing PROXY protocol payload\n  - identifying the PROXY protocol version\n- Supports both of the version: V1 and V2 protocol\n- Also supports TypeScript\n- It doesn't requre the extra dependencies\n\nUsage\n--\n\nSee also [examples](./example) and TSDoc.\n\n### Build (and identity the protocol version)\n\n#### V1 protocol\n\n```JavaScript\nconst proxyProtocol = require('proxy-protocol-js');\n\nconst src = new proxyProtocol.Peer('127.0.0.1', 12345);\nconst dst = new proxyProtocol.Peer('192.0.2.1', 54321);\nconst protocolText = new proxyProtocol.V1ProxyProtocol(\n  proxyProtocol.INETProtocol.TCP4,\n  src,\n  dst,\n).build();\nconsole.log(protocolText); // =\u003e PROXY TCP4 127.0.0.1 192.0.2.1 12345 54321\\r\\n\n\nconst identifiedProtocolVersion = proxyProtocol.ProxyProtocolIdentifier.identify(protocolText);\nconsole.log(identifiedProtocolVersion); // =\u003e proxyProtocol.ProxyProtocolVersion.V1 (= 0xx10)\n```\n\n#### V2 protocol\n\n```JavaScript\nconst proxyProtocol = require('proxy-protocol-js');\n\nconst proto = new proxyProtocol.V2ProxyProtocol(\n  proxyProtocol.Command.LOCAL,\n  proxyProtocol.TransportProtocol.DGRAM,\n  new proxyProtocol.IPv4ProxyAddress(\n    proxyProtocol.IPv4Address.createFrom([127, 0, 0, 1]),\n    12345,\n    proxyProtocol.IPv4Address.createFrom([192, 0, 2, 1]),\n    54321,\n  ),\n).build();\nconsole.log(proto);\n\nconst identifiedProtocolVersion = proxyProtocol.ProxyProtocolIdentifier.identify(proto);\nconsole.log(identifiedProtocolVersion); // =\u003e proxyProtocol.ProxyProtocolVersion.V2 (= 0x20)\n```\n\n### Parse\n\n#### V1 protocol\n\n```JavaScript\nconst proxyProtocol = require('proxy-protocol');\n\nconst protocolText = 'PROXY TCP4 127.0.0.1 192.0.2.1 12345 54321\\r\\n';\nconst proto = proxyProtocol.V1ProxyProtocol.parse(protocolText);\nconsole.log(proto);\n// =\u003e V1ProxyProtocol {\n//      inetProtocol: 'TCP4',\n//      source: Host { ipAddress: '127.0.0.1', port: 12345 },\n//      destination: Host { ipAddress: '192.0.2.1', port: 54321 },\n//      data: '' }\n```\n\n#### V2 protocol\n\n```JavaScript\nconst proxyProtocol = require('proxy-protocol-js');\n\nconst protoBin = new Uint8Array([13, 10, 13, 10, 0, 13, 10, 81, 85, 73, 84, 10, 32, 18, 0, 12, 127, 0, 0, 1, 192, 0, 2, 1, 48, 57, 212, 49]);\nconst proto = proxyProtocol.V2ProxyProtocol.parse(protoBin);\nconsole.log(proto);\n// =\u003e V2ProxyProtocol {\n//   command: 0,\n//   transportProtocol: 2,\n//   proxyAddress:\n//    IPv4ProxyAddress {\n//      sourceAddress: IPv4Address { address: [Array] },\n//      sourcePort: 12345,\n//      destinationAddress: IPv4Address { address: [Array] },\n//      destinationPort: 54321 },\n//   data: Uint8Array [],\n//   addressFamilyType: 16 }`\n```\n\nPerformance\n--\n\nThe result of the comparison between this library (`proxy-protocol-js`) and [proxy-protocol](https://www.npmjs.com/package/proxy-protocol) is here:\n\n```\nproxy-protocol.parse x 246,423 ops/sec ±3.10% (32 runs sampled)\nproxy-protocol-js.parse x 481,388 ops/sec ±5.32% (69 runs sampled)\nFastest is proxy-protocol-js.parse\n```\n\n(moreover, `proxy-protocol-js`'s benchmark contains unnecessary dummy codes for fairness)\n\nThis benchmark run on the node v10.15.3 and the code is [here](./bench).\n\nAuthor\n--\n\nmoznion (\u003cmoznion@gmail.com\u003e)\n\nLicense\n--\n\n[MIT](./LICENSE)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoznion%2Fproxy-protocol-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoznion%2Fproxy-protocol-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoznion%2Fproxy-protocol-js/lists"}