-
Notifications
You must be signed in to change notification settings - Fork 10
/
utils.js
36 lines (30 loc) · 920 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* A very simple node.js HTTP proxy providing usage rate limiting using Redis.
*
* Author: Josh Devins ([email protected], http://joshdevins.net)
*/
/**
* Returns the number of seconds since epoch, aka Unix time.
*/
exports.getSecondsSinceEpoch = function() {
return Math.round(new Date().getTime() / 1000);
}
/**
* Merges sets of headers very simply.
*/
exports.mergeHeaders = function(headers1, headers2) {
for (attrname in headers2) {
headers1[attrname] = headers2[attrname];
}
}
/**
* Given a Node ServerRequest object, determine the new X-Forwarded-For header for upstream server in the proxied request.
*/
exports.getNewXForwardedForHeader = function(request) {
var value = request.headers['x-forwarded-for'];
if (value != null) {
return value + ", " + request.socket.remoteAddress;
} else {
return request.socket.remoteAddress;
}
}