Skip to content

Commit

Permalink
fix(http): support multiple options in connection header for websocket (
Browse files Browse the repository at this point in the history
  • Loading branch information
silen-z committed Jul 24, 2021
1 parent 3e08b6a commit 74c7559
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 12 additions & 0 deletions cli/tests/unit/http_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,18 @@ unitTest(function httpUpgradeWebSocketLowercaseUpgradeHeader() {
assertEquals(response.status, 101);
});

unitTest(function httpUpgradeWebSocketMultipleConnectionOptions() {
const request = new Request("https://deno.land/", {
headers: {
connection: "keep-alive, upgrade",
upgrade: "websocket",
"sec-websocket-key": "dGhlIHNhbXBsZSBub25jZQ==",
},
});
const { response } = Deno.upgradeWebSocket(request);
assertEquals(response.status, 101);
});

unitTest({ perms: { net: true } }, async function httpCookieConcatenation() {
const promise = (async () => {
const listener = Deno.listen({ port: 4501 });
Expand Down
10 changes: 9 additions & 1 deletion extensions/http/01_http.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
const {
ArrayPrototypeIncludes,
ArrayPrototypePush,
ArrayPrototypeSome,
Promise,
StringPrototypeIncludes,
StringPrototypeToLowerCase,
StringPrototypeSplit,
Symbol,
SymbolAsyncIterator,
Expand Down Expand Up @@ -321,7 +323,13 @@
);
}

if (request.headers.get("connection")?.toLowerCase() !== "upgrade") {
const connection = request.headers.get("connection");
const connectionHasUpgradeOption = connection !== null &&
ArrayPrototypeSome(
StringPrototypeSplit(connection, /\s*,\s*/),
(option) => StringPrototypeToLowerCase(option) === "upgrade",
);
if (!connectionHasUpgradeOption) {
throw new TypeError(
"Invalid Header: 'connection' header must be 'Upgrade'",
);
Expand Down

0 comments on commit 74c7559

Please sign in to comment.