{"name":"@fastify/proxy-addr","version":"4.0.0","keywords":["ip","proxy","x-forwarded-for"],"author":{"name":"Douglas Christopher Wilson","email":"doug@somethingdoug.com"},"license":"MIT","_id":"@fastify/proxy-addr@4.0.0","maintainers":[{"name":"delvedor","email":"tommydelved@gmail.com"},{"name":"matteo.collina","email":"hello@matteocollina.com"},{"name":"jsumners","email":"james.sumners@gmail.com"}],"homepage":"https://github.com/fastify/proxy-addr#readme","bugs":{"url":"https://github.com/fastify/proxy-addr/issues"},"dist":{"shasum":"478938c185835e2e98a4ccdb06e1ba3c957e89b8","tarball":"http://registry-npm.ywwl.com/@fastify/proxy-addr/download/@fastify/proxy-addr-4.0.0.tgz","fileCount":4,"integrity":"sha512-Xt8eu+NAl7rEWQ17B0Hdc0Snhaot2ZXL0c8IKrJBcV4E1jUM2baBiu00vZx9o2DGbV5irfDjcVdaqri/YhwDdw==","signatures":[{"sig":"MEQCIDhdhxl8D93t3dmEAhVAbGt98ZekG6lbwaVfSQ9EpkvwAiAOvN4oTJ+pmavuAGY7K6XkBBqafwbXhNW1916pOJzoLg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":12089,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJijfLAACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpwkxAAoZMmyr7c8aj74Vj238Jf2PAKTaM+wLnVq0x0UlkZn1SCDbNC\r\n8cTt/Lm6uoQjcDXEBMmsGlbUgoVLBFlQwPuqm+oall0FcmswiqEwFs4KPQoV\r\nGB106aTymmiAekDKWSDP2W/X2bLVoiDycEtHPEAi4BrTBvi812OsTMAdwtjr\r\nDzKTvAc13raGzO8/YMpQRgaQucaQOCwvm9OiWoVDN5/pB36UYQYdiBgWYydE\r\nTtsT4NveakRGy084vjMKFcDZ2bdeQtITeqtvsqLqazWug5vt/xpPOS3h74Dv\r\n41oFNIrVn9OeY+LP9RSjRexfW+3opsq1HrCT/SjtisxoWD1pdpMgqJIS29F9\r\nfzwh5SfHqMYe5HeA3RGLisGjA9cDipmpWUQ7VShSvdkneYekKResWbLqPBx9\r\neJxfT06H7JDM7VThtSQGap/BLHuk/OFm57graY8wShpMZtZYoqRylDFf5tEA\r\n3V0iVVRfHoEGRxO6zCQIfxIbLLBwUwdmzVqltz9DRask83M0R0hMColpPTa0\r\nBKqio6nwRTTIRMQlvRgHaJo3II+azuPug9CItoPpx4arYf+rdOz9eI2Cns1x\r\n/E3te8Uiy5JCfpKYFArtGT/CTRNm7HTZIZQZ3fv1EeLxFxPwiizl9S2UOoP9\r\n9IH3XcUGrnyEnMRwM1fdAJuUWT7iLvd86Gs=\r\n=xyja\r\n-----END PGP SIGNATURE-----\r\n","size":4330,"noattachment":false,"key":"/@fastify/proxy-addr/-/@fastify/proxy-addr-4.0.0.tgz"},"gitHead":"c846304b73239e4aaef95b29c08f43c071e9bd05","scripts":{"test":"standard && tap","bench":"node benchmark/index.js"},"_npmUser":{"name":"matteo.collina","email":"hello@matteocollina.com"},"repository":{"url":"git+https://github.com/fastify/proxy-addr.git","type":"git"},"_npmVersion":"8.5.5","description":"Determine address of proxied request","directories":{},"_nodeVersion":"16.15.0","dependencies":{"ipaddr.js":"^2.0.0","@fastify/forwarded":"^2.0.0"},"_hasShrinkwrap":false,"devDependencies":{"tap":"^16.0.0","standard":"^17.0.0","benchmark":"2.1.4","beautify-benchmark":"0.2.4"},"_npmOperationalInternal":{"tmp":"tmp/proxy-addr_4.0.0_1653469888726_0.58643301527822","host":"s3://npm-registry-packages"},"readme":"# proxy-addr\n\n[![CI](https://github.com/fastify/proxy-addr/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/proxy-addr/actions/workflows/ci.yml)\n[![NPM version](https://img.shields.io/npm/v/@fastify/proxy-addr.svg?style=flat)](https://www.npmjs.com/package/@fastify/proxy-addr)\n[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)\n\nDetermine the address of a proxied request.\n\nForked from https://github.com/jshttp/proxy-addr to address https://github.com/jshttp/forwarded/pull/9.\n\n## Install\n\n```sh\n$ npm i @fastify/proxy-addr\n```\n\n## API\n\n<!-- eslint-disable no-unused-vars -->\n\n```js\nconst proxyaddr = require('@fastify/proxy-addr')\n```\n\n### proxyaddr(req, trust)\n\nReturn the address of the request, using the given `trust` parameter.\n\nThe `trust` argument is a function that returns `true` if you trust\nthe address, `false` if you don't. The closest untrusted address is\nreturned.\n\n<!-- eslint-disable no-undef -->\n\n```js\nproxyaddr(req, function (addr) { return addr === '127.0.0.1' })\nproxyaddr(req, function (addr, i) { return i < 1 })\n```\n\nThe `trust` argument may also be a single IP address string or an\narray of trusted addresses, as plain IP addresses, CIDR-formatted\nstrings, or IP/netmask strings.\n\n<!-- eslint-disable no-undef -->\n\n```js\nproxyaddr(req, '127.0.0.1')\nproxyaddr(req, ['127.0.0.0/8', '10.0.0.0/8'])\nproxyaddr(req, ['127.0.0.0/255.0.0.0', '192.168.0.0/255.255.0.0'])\n```\n\nThis module also supports IPv6. Your IPv6 addresses will be normalized\nautomatically (i.e. `fe80::00ed:1` equals `fe80:0:0:0:0:0:ed:1`).\n\n<!-- eslint-disable no-undef -->\n\n```js\nproxyaddr(req, '::1')\nproxyaddr(req, ['::1/128', 'fe80::/10'])\n```\n\nThis module will automatically work with IPv4-mapped IPv6 addresses\nas well to support node.js in IPv6-only mode. This means that you do\nnot have to specify both `::ffff:a00:1` and `10.0.0.1`.\n\nAs a convenience, this module also takes certain pre-defined names\nin addition to IP addresses, which expand into IP addresses:\n\n<!-- eslint-disable no-undef -->\n\n```js\nproxyaddr(req, 'loopback')\nproxyaddr(req, ['loopback', 'fc00:ac:1ab5:fff::1/64'])\n```\n\n  * `loopback`: IPv4 and IPv6 loopback addresses (like `::1` and\n    `127.0.0.1`).\n  * `linklocal`: IPv4 and IPv6 link-local addresses (like\n    `fe80::1:1:1:1` and `169.254.0.1`).\n  * `uniquelocal`: IPv4 private addresses and IPv6 unique-local\n    addresses (like `fc00:ac:1ab5:fff::1` and `192.168.0.1`).\n\nWhen `trust` is specified as a function, it will be called for each\naddress to determine if it is a trusted address. The function is\ngiven two arguments: `addr` and `i`, where `addr` is a string of\nthe address to check and `i` is a number that represents the distance\nfrom the socket address.\n\n### proxyaddr.all(req, [trust])\n\nReturn all the request addresses, optionally stopping at the\nfirst untrusted. This array is ordered from closest to furthest\n(i.e. `arr[0] === req.connection.remoteAddress`).\n\n<!-- eslint-disable no-undef -->\n\n```js\nproxyaddr.all(req)\n```\n\nThe optional `trust` argument takes the same arguments as `trust`\ndoes in `proxyaddr(req, trust)`.\n\n<!-- eslint-disable no-undef -->\n\n```js\nproxyaddr.all(req, 'loopback')\n```\n\n### proxyaddr.compile(val)\n\nCompiles argument `val` into a `trust` function. This function takes\nthe same arguments as `trust` does in `proxyaddr(req, trust)` and\nreturns a function suitable for `proxyaddr(req, trust)`.\n\n<!-- eslint-disable no-undef, no-unused-vars -->\n\n```js\nconst trust = proxyaddr.compile('loopback')\nconst addr = proxyaddr(req, trust)\n```\n\nThis function is meant to be optimized for use against every request.\nIt is recommended that a trust function be compiled up-front for the\ntrusted configuration and passed to proxyaddr(req, trust) for each request.\n\n## Testing\n\n```sh\n$ npm test\n```\n\n## Benchmarks\n\n```sh\n$ npm run bench\n```\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","publish_time":1653469888877,"_cnpm_publish_time":1653469888877,"dist-tags":{"latest":"5.1.2","next":"5.0.0"}}