-
Notifications
You must be signed in to change notification settings - Fork 4
/
filter-headers.js
30 lines (29 loc) · 947 Bytes
/
filter-headers.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
'use strict';
const ACCEPT_HEADERS = [
'accept-language',
'referer',
'user-agent',
'x-request-uri',
'x-request-host'
];
/**
* Filter the request headers that are passed to fragment request.
* @callback filterHeaders
*
* @param {Object} attributes - Attributes object of the fragment node
* @param {string} attributes.public - Denotes the public fragment.
* @param {Object} request - HTTP Request object
* @param {Object} request.headers - request header object
* @returns {Object} New filtered header object
*/
module.exports = (attributes, request) => {
const { public: isPublic } = attributes;
const { headers = {} } = request;
// Headers are not forwarded to public fragment for security reasons
return isPublic
? {}
: ACCEPT_HEADERS.reduce((newHeaders, key) => {
headers[key] && (newHeaders[key] = headers[key]);
return newHeaders;
}, {});
};