Merge "LOG SQL dump files getting installed"
[sdnc/oam.git] / dgbuilder / dgeflows / node_modules / express / node_modules / proxy-addr / README.md
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
9 Determine address of proxied request
10
11 ## Install
12
13 ```sh
14 $ npm install proxy-addr
15 ```
16
17 ## API
18
19 ```js
20 var proxyaddr = require('proxy-addr')
21 ```
22
23 ### proxyaddr(req, trust)
24
25 Return the address of the request, using the given `trust` parameter.
26
27 The `trust` argument is a function that returns `true` if you trust
28 the address, `false` if you don't. The closest untrusted address is
29 returned.
30
31 ```js
32 proxyaddr(req, function(addr){ return addr === '127.0.0.1' })
33 proxyaddr(req, function(addr, i){ return i < 1 })
34 ```
35
36 The `trust` argument may also be a single IP address string or an
37 array of trusted addresses, as plain IP addresses, CIDR-formatted
38 strings, or IP/netmask strings.
39
40 ```js
41 proxyaddr(req, '127.0.0.1')
42 proxyaddr(req, ['127.0.0.0/8', '10.0.0.0/8'])
43 proxyaddr(req, ['127.0.0.0/255.0.0.0', '192.168.0.0/255.255.0.0'])
44 ```
45
46 This module also supports IPv6. Your IPv6 addresses will be normalized
47 automatically (i.e. `fe80::00ed:1` equals `fe80:0:0:0:0:0:ed:1`).
48
49 ```js
50 proxyaddr(req, '::1')
51 proxyaddr(req, ['::1/128', 'fe80::/10'])
52 proxyaddr(req, ['fe80::/ffc0::'])
53 ```
54
55 This module will automatically work with IPv4-mapped IPv6 addresses
56 as well to support node.js in IPv6-only mode. This means that you do
57 not have to specify both `::ffff:a00:1` and `10.0.0.1`.
58
59 As a convenience, this module also takes certain pre-defined names
60 in addition to IP addresses, which expand into IP addresses:
61
62 ```js
63 proxyaddr(req, 'loopback')
64 proxyaddr(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
74 When `trust` is specified as a function, it will be called for each
75 address to determine if it is a trusted address. The function is
76 given two arguments: `addr` and `i`, where `addr` is a string of
77 the address to check and `i` is a number that represents the distance
78 from the socket address.
79
80 ### proxyaddr.all(req, [trust])
81
82 Return all the addresses of the request, optionally stopping at the
83 first untrusted. This array is ordered from closest to furthest
84 (i.e. `arr[0] === req.connection.remoteAddress`).
85
86 ```js
87 proxyaddr.all(req)
88 ```
89
90 The optional `trust` argument takes the same arguments as `trust`
91 does in `proxyaddr(req, trust)`.
92
93 ```js
94 proxyaddr.all(req, 'loopback')
95 ```
96
97 ### proxyaddr.compile(val)
98
99 Compiles argument `val` into a `trust` function. This function takes
100 the same arguments as `trust` does in `proxyaddr(req, trust)` and
101 returns a function suitable for `proxyaddr(req, trust)`.
102
103 ```js
104 var trust = proxyaddr.compile('localhost')
105 var addr  = proxyaddr(req, trust)
106 ```
107
108 This function is meant to be optimized for use against every request.
109 It is recommend to compile a trust function up-front for the trusted
110 configuration 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?style=flat
129 [npm-url]: https://npmjs.org/package/proxy-addr
130 [node-version-image]: https://img.shields.io/node/v/proxy-addr.svg?style=flat
131 [node-version-url]: http://nodejs.org/download/
132 [travis-image]: https://img.shields.io/travis/jshttp/proxy-addr.svg?style=flat
133 [travis-url]: https://travis-ci.org/jshttp/proxy-addr
134 [coveralls-image]: https://img.shields.io/coveralls/jshttp/proxy-addr.svg?style=flat
135 [coveralls-url]: https://coveralls.io/r/jshttp/proxy-addr?branch=master
136 [downloads-image]: https://img.shields.io/npm/dm/proxy-addr.svg?style=flat
137 [downloads-url]: https://npmjs.org/package/proxy-addr