Skip to content

Commit cf06a7c

Browse files
authored
refactor(ext/http): use String.prototype.trim() instead of regex (#17722)
1 parent 68008be commit cf06a7c

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

ext/http/01_http.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const {
5151
StringPrototypeIncludes,
5252
StringPrototypeToLowerCase,
5353
StringPrototypeSplit,
54+
StringPrototypeTrim,
5455
Symbol,
5556
SymbolAsyncIterator,
5657
TypeError,
@@ -393,8 +394,9 @@ function upgradeWebSocket(request, options = {}) {
393394
const upgrade = request.headers.get("upgrade");
394395
const upgradeHasWebSocketOption = upgrade !== null &&
395396
ArrayPrototypeSome(
396-
StringPrototypeSplit(upgrade, /\s*,\s*/),
397-
(option) => StringPrototypeToLowerCase(option) === "websocket",
397+
StringPrototypeSplit(upgrade, ","),
398+
(option) =>
399+
StringPrototypeToLowerCase(StringPrototypeTrim(option)) === "websocket",
398400
);
399401
if (!upgradeHasWebSocketOption) {
400402
throw new TypeError(
@@ -405,8 +407,9 @@ function upgradeWebSocket(request, options = {}) {
405407
const connection = request.headers.get("connection");
406408
const connectionHasUpgradeOption = connection !== null &&
407409
ArrayPrototypeSome(
408-
StringPrototypeSplit(connection, /\s*,\s*/),
409-
(option) => StringPrototypeToLowerCase(option) === "upgrade",
410+
StringPrototypeSplit(connection, ","),
411+
(option) =>
412+
StringPrototypeToLowerCase(StringPrototypeTrim(option)) === "upgrade",
410413
);
411414
if (!connectionHasUpgradeOption) {
412415
throw new TypeError(

0 commit comments

Comments
 (0)