mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix(http): support multiple options in connection header for websocket (#11505)
Fixes #11494
This commit is contained in:
parent
3e08b6ae89
commit
74c7559d20
2 changed files with 21 additions and 1 deletions
|
@ -693,6 +693,18 @@ unitTest(function httpUpgradeWebSocketLowercaseUpgradeHeader() {
|
||||||
assertEquals(response.status, 101);
|
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() {
|
unitTest({ perms: { net: true } }, async function httpCookieConcatenation() {
|
||||||
const promise = (async () => {
|
const promise = (async () => {
|
||||||
const listener = Deno.listen({ port: 4501 });
|
const listener = Deno.listen({ port: 4501 });
|
||||||
|
|
|
@ -22,8 +22,10 @@
|
||||||
const {
|
const {
|
||||||
ArrayPrototypeIncludes,
|
ArrayPrototypeIncludes,
|
||||||
ArrayPrototypePush,
|
ArrayPrototypePush,
|
||||||
|
ArrayPrototypeSome,
|
||||||
Promise,
|
Promise,
|
||||||
StringPrototypeIncludes,
|
StringPrototypeIncludes,
|
||||||
|
StringPrototypeToLowerCase,
|
||||||
StringPrototypeSplit,
|
StringPrototypeSplit,
|
||||||
Symbol,
|
Symbol,
|
||||||
SymbolAsyncIterator,
|
SymbolAsyncIterator,
|
||||||
|
@ -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(
|
throw new TypeError(
|
||||||
"Invalid Header: 'connection' header must be 'Upgrade'",
|
"Invalid Header: 'connection' header must be 'Upgrade'",
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue