mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 08:09:08 -05:00
perf(fetch/headers): optimize appendHeader (#12234)
Use a single regex to check for `\0`, `\n`, `\r` instead of 3 `String.includes(...)` calls
This commit is contained in:
parent
b095157c1d
commit
6c007aa5ab
1 changed files with 6 additions and 11 deletions
|
@ -37,7 +37,6 @@
|
||||||
SymbolFor,
|
SymbolFor,
|
||||||
SymbolIterator,
|
SymbolIterator,
|
||||||
StringPrototypeReplaceAll,
|
StringPrototypeReplaceAll,
|
||||||
StringPrototypeIncludes,
|
|
||||||
TypeError,
|
TypeError,
|
||||||
} = window.__bootstrap.primordials;
|
} = window.__bootstrap.primordials;
|
||||||
|
|
||||||
|
@ -94,6 +93,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
* https://fetch.spec.whatwg.org/#concept-headers-append
|
||||||
* @param {Headers} headers
|
* @param {Headers} headers
|
||||||
|
@ -108,11 +111,7 @@
|
||||||
if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) {
|
if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) {
|
||||||
throw new TypeError("Header name is not valid.");
|
throw new TypeError("Header name is not valid.");
|
||||||
}
|
}
|
||||||
if (
|
if (RegExpPrototypeTest(ILLEGAL_VALUE_CHARS, value)) {
|
||||||
StringPrototypeIncludes(value, "\x00") ||
|
|
||||||
StringPrototypeIncludes(value, "\x0A") ||
|
|
||||||
StringPrototypeIncludes(value, "\x0D")
|
|
||||||
) {
|
|
||||||
throw new TypeError("Header value is not valid.");
|
throw new TypeError("Header value is not valid.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,11 +371,7 @@
|
||||||
if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) {
|
if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) {
|
||||||
throw new TypeError("Header name is not valid.");
|
throw new TypeError("Header name is not valid.");
|
||||||
}
|
}
|
||||||
if (
|
if (RegExpPrototypeTest(ILLEGAL_VALUE_CHARS, value)) {
|
||||||
StringPrototypeIncludes(value, "\x00") ||
|
|
||||||
StringPrototypeIncludes(value, "\x0A") ||
|
|
||||||
StringPrototypeIncludes(value, "\x0D")
|
|
||||||
) {
|
|
||||||
throw new TypeError("Header value is not valid.");
|
throw new TypeError("Header value is not valid.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue