1 | 'use strict';
|
2 |
|
3 | var debug = require('debug')('plugin:header-clean');
|
4 | const headerCharRegex = /[^\t\x20-\x7e\x80-\xff]/g
|
5 |
|
6 |
|
7 | module.exports.init = function(/*config, logger, stats*/) {
|
8 | return {
|
9 | onrequest: function(req, res, next) {
|
10 | Object.keys(req.headers).forEach(function(key) {
|
11 | var val = req.headers[key]
|
12 | if (typeof val === 'string') {
|
13 | var newVal = val.replace(headerCharRegex, '')
|
14 | if (debug.enabled && val.match(headerCharRegex)) {
|
15 | debug('Cleaned header %s. Old: %s. New: %s', key, val, newVal);
|
16 | }
|
17 | req.headers[key] = newVal
|
18 | }
|
19 | });
|
20 | next();
|
21 | },
|
22 | };
|
23 | } |
\ | No newline at end of file |