perf(fetch/headers): optimize appendHeader
Use a single regex to check for `\0`, `\n`, `\r` instead of 3 `String.includes(...)` calls
SymbolFor,
SymbolIterator,
StringPrototypeReplaceAll,
- StringPrototypeIncludes,
TypeError,
} = window.__bootstrap.primordials;
}
}
+ // Regex matching illegal chars in a header value
+ // deno-lint-ignore no-control-regex
+ const ILLEGAL_VALUE_CHARS = /[\x00\x0A\x0D]/;
+
/**
* https://fetch.spec.whatwg.org/#concept-headers-append
* @param {Headers} headers
if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) {
throw new TypeError("Header name is not valid.");
}
- if (
- StringPrototypeIncludes(value, "\x00") ||
- StringPrototypeIncludes(value, "\x0A") ||
- StringPrototypeIncludes(value, "\x0D")
- ) {
+ if (RegExpPrototypeTest(ILLEGAL_VALUE_CHARS, value)) {
throw new TypeError("Header value is not valid.");
}
if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) {
throw new TypeError("Header name is not valid.");
}
- if (
- StringPrototypeIncludes(value, "\x00") ||
- StringPrototypeIncludes(value, "\x0A") ||
- StringPrototypeIncludes(value, "\x0D")
- ) {
+ if (RegExpPrototypeTest(ILLEGAL_VALUE_CHARS, value)) {
throw new TypeError("Header value is not valid.");
}
