Skip to content

Commit

Permalink
feat(utils): add headercleanup helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Apr 7, 2021
1 parent d9bffab commit 4d28f25
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ class Utils {
logLevelForStatusCode(status) {
return lookupBackendResponses(status).level;
}

/**
* Cleans up a header value by stripping invalid characters and truncating to 1024 chars
* @param {string} value a header value
* @returns a valid header value
*/
cleanupHeaderValue(value) {
return value.replace(/[^\t\u0020-\u007E\u0080-\u00FF]/g, '').substr(0, 1024);
}
}

module.exports = new Utils();
28 changes: 28 additions & 0 deletions test/headercleanup.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4d28f25

Please sign in to comment.