Skip to content

Commit a8f6d79

Browse files
committed
Simplify header validity check
See: nodejs/node@9f55eac See: nodejs/node@862389b
1 parent c0950b7 commit a8f6d79

File tree

2 files changed

+4
-114
lines changed

2 files changed

+4
-114
lines changed

src/common.js

Lines changed: 0 additions & 111 deletions
This file was deleted.

src/headers.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@
55
* Headers class offers convenient helpers
66
*/
77

8-
import { checkInvalidHeaderChar, checkIsHttpToken } from './common.js';
8+
const invalidTokenRegex = /[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/;
9+
const invalidHeaderCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
910

1011
function sanitizeName(name) {
1112
name += '';
12-
if (!checkIsHttpToken(name)) {
13+
if (invalidTokenRegex.test(name)) {
1314
throw new TypeError(`${name} is not a legal HTTP header name`);
1415
}
1516
return name.toLowerCase();
1617
}
1718

1819
function sanitizeValue(value) {
1920
value += '';
20-
if (checkInvalidHeaderChar(value)) {
21+
if (invalidHeaderCharRegex.test(value)) {
2122
throw new TypeError(`${value} is not a legal HTTP header value`);
2223
}
2324
return value;

0 commit comments

Comments
 (0)