forked from madglory/edgescape-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
28 lines (25 loc) · 775 Bytes
/
index.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
'use strict';
module.exports = function(options) {
var header = (options && options.header) ? options.header : 'x-akamai-edgescape';
return function(req, res, next) {
if(req.headers[header]) {
req.akamai = req.akamai || {};
req.akamai.edgescape = req.akamai.edgescape || {};
var pairs = req.headers[header].split(',');
var edgescape = {};
pairs.forEach(function(pair) {
pair = pair.split('=');
switch(pair[0]) {
case 'area_code':
case 'zip':
case 'asnum':
req.akamai.edgescape[pair[0]] = pair[1].split('+');
break;
default:
req.akamai.edgescape[pair[0]] = decodeURIComponent(pair[1] || '');
}
});
}
next();
}
};