diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-09-26 20:19:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-26 20:19:02 +0200 |
commit | 6c007aa5abde06fc7d9d57b6a3a8153727e5ccdc (patch) | |
tree | 4cf293279d8896c56868e838c7547a0c8085c3aa /ext/fetch/20_headers.js | |
parent | b095157c1d9ffd979a82f559aa488e35c2e7f392 (diff) |
perf(fetch/headers): optimize appendHeader (#12234)
Use a single regex to check for `\0`, `\n`, `\r` instead of 3 `String.includes(...)` calls
Diffstat (limited to 'ext/fetch/20_headers.js')
-rw-r--r-- | ext/fetch/20_headers.js | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/ext/fetch/20_headers.js b/ext/fetch/20_headers.js index a99a297b3..67c5d0e65 100644 --- a/ext/fetch/20_headers.js +++ b/ext/fetch/20_headers.js @@ -37,7 +37,6 @@ SymbolFor, SymbolIterator, StringPrototypeReplaceAll, - StringPrototypeIncludes, TypeError, } = 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 * @param {Headers} headers @@ -108,11 +111,7 @@ 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."); } @@ -372,11 +371,7 @@ 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."); } |