aboutsummaryrefslogtreecommitdiff
path: root/node_modules/forwarded/index.js
diff options
context:
space:
mode:
authorWaref Haque <warefhaque@Warefs-MacBook-Pro.local>2016-07-17 20:24:49 +0000
committerWaref Haque <warefhaque@Warefs-MacBook-Pro.local>2016-07-17 20:24:49 +0000
commite58943c3e620f05937656fdde032254ae3373f36 (patch)
tree77072aa55efa1753c8c8ae584669cf3589551268 /node_modules/forwarded/index.js
parent55098c767afb0b119aaeda330eaedba5c1a87dc3 (diff)
redirect commit
Diffstat (limited to 'node_modules/forwarded/index.js')
-rw-r--r--node_modules/forwarded/index.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/node_modules/forwarded/index.js b/node_modules/forwarded/index.js
new file mode 100644
index 0000000..2f5c340
--- /dev/null
+++ b/node_modules/forwarded/index.js
@@ -0,0 +1,35 @@
+/*!
+ * forwarded
+ * Copyright(c) 2014 Douglas Christopher Wilson
+ * MIT Licensed
+ */
+
+/**
+ * Module exports.
+ */
+
+module.exports = forwarded
+
+/**
+ * Get all addresses in the request, using the `X-Forwarded-For` header.
+ *
+ * @param {Object} req
+ * @api public
+ */
+
+function forwarded(req) {
+ if (!req) {
+ throw new TypeError('argument req is required')
+ }
+
+ // simple header parsing
+ var proxyAddrs = (req.headers['x-forwarded-for'] || '')
+ .split(/ *, */)
+ .filter(Boolean)
+ .reverse()
+ var socketAddr = req.connection.remoteAddress
+ var addrs = [socketAddr].concat(proxyAddrs)
+
+ // return all addresses
+ return addrs
+}