socketioMEANseed/server/node_modules/proxy-addr/README.md
server/node_modules/proxy-addr/README.mdRaw
1# proxy-addr
2
3[![NPM Version][npm-image]][npm-url]
4[![NPM Downloads][downloads-image]][downloads-url]
5[![Node.js Version][node-version-image]][node-version-url]
6[![Build Status][travis-image]][travis-url]
7[![Test Coverage][coveralls-image]][coveralls-url]
8
9Determine address of proxied request
10
11## Install
12
13```sh
14$ npm install proxy-addr
15```
16
17## API
18
19```js
20var proxyaddr = require('proxy-addr')
21```
22
23### proxyaddr(req, trust)
24
25Return the address of the request, using the given `trust` parameter.
26
27The `trust` argument is a function that returns `true` if you trust
28the address, `false` if you don't. The closest untrusted address is
29returned.
30
31```js
32proxyaddr(req, function(addr){ return addr === '127.0.0.1' })
33proxyaddr(req, function(addr, i){ return i < 1 })
34```
35
36The `trust` arugment may also be a single IP address string or an
37array of trusted addresses, as plain IP addresses, CIDR-formatted
38strings, or IP/netmask strings.
39
40```js
41proxyaddr(req, '127.0.0.1')
42proxyaddr(req, ['127.0.0.0/8', '10.0.0.0/8'])
43proxyaddr(req, ['127.0.0.0/255.0.0.0', '192.168.0.0/255.255.0.0'])
44```
45
46This module also supports IPv6. Your IPv6 addresses will be normalized
47automatically (i.e. `fe80::00ed:1` equals `fe80:0:0:0:0:0:ed:1`).
48
49```js
50proxyaddr(req, '::1')
51proxyaddr(req, ['::1/128', 'fe80::/10'])
52proxyaddr(req, ['fe80::/ffc0::'])
53```
54
55This module will automatically work with IPv4-mapped IPv6 addresses
56as well to support node.js in IPv6-only mode. This means that you do
57not have to specify both `::ffff:a00:1` and `10.0.0.1`.
58
59As a convenience, this module also takes certain pre-defined names
60in addition to IP addresses, which expand into IP addresses:
61
62```js
63proxyaddr(req, 'loopback')
64proxyaddr(req, ['loopback', 'fc00:ac:1ab5:fff::1/64'])
65```
66
67 * `loopback`: IPv4 and IPv6 loopback addresses (like `::1` and
68 `127.0.0.1`).
69 * `linklocal`: IPv4 and IPv6 link-local addresses (like
70 `fe80::1:1:1:1` and `169.254.0.1`).
71 * `uniquelocal`: IPv4 private addresses and IPv6 unique-local
72 addresses (like `fc00:ac:1ab5:fff::1` and `192.168.0.1`).
73
74When `trust` is specified as a function, it will be called for each
75address to determine if it is a trusted address. The function is
76given two arguments: `addr` and `i`, where `addr` is a string of
77the address to check and `i` is a number that represents the distance
78from the socket address.
79
80### proxyaddr.all(req, [trust])
81
82Return all the addresses of the request, optionally stopping at the
83first untrusted. This array is ordered from closest to furthest
84(i.e. `arr[0] === req.connection.remoteAddress`).
85
86```js
87proxyaddr.all(req)
88```
89
90The optional `trust` argument takes the same arguments as `trust`
91does in `proxyaddr(req, trust)`.
92
93```js
94proxyaddr.all(req, 'loopback')
95```
96
97### proxyaddr.compile(val)
98
99Compiles argument `val` into a `trust` function. This function takes
100the same arguments as `trust` does in `proxyaddr(req, trust)` and
101returns a function suitable for `proxyaddr(req, trust)`.
102
103```js
104var trust = proxyaddr.compile('localhost')
105var addr = proxyaddr(req, trust)
106```
107
108This function is meant to be optimized for use against every request.
109It is recommend to compile a trust function up-front for the trusted
110configuration and pass that to `proxyaddr(req, trust)` for each request.
111
112## Testing
113
114```sh
115$ npm test
116```
117
118## Benchmarks
119
120```sh
121$ npm run-script bench
122```
123
124## License
125
126[MIT](LICENSE)
127
128[npm-image]: https://img.shields.io/npm/v/proxy-addr.svg
129[npm-url]: https://npmjs.org/package/proxy-addr
130[node-version-image]: https://img.shields.io/node/v/proxy-addr.svg
131[node-version-url]: http://nodejs.org/download/
132[travis-image]: https://img.shields.io/travis/jshttp/proxy-addr/master.svg
133[travis-url]: https://travis-ci.org/jshttp/proxy-addr
134[coveralls-image]: https://img.shields.io/coveralls/jshttp/proxy-addr/master.svg
135[coveralls-url]: https://coveralls.io/r/jshttp/proxy-addr?branch=master
136[downloads-image]: https://img.shields.io/npm/dm/proxy-addr.svg
137[downloads-url]: https://npmjs.org/package/proxy-addr