mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
fix(http/ws): case insensitive connection header (#11489)
The "connection" header should be case insensitive: https://datatracker.ietf.org/doc/html/rfc7230#section-6.1
This commit is contained in:
parent
4861b13aab
commit
8b34f07bb0
2 changed files with 32 additions and 2 deletions
|
@ -642,7 +642,7 @@ unitTest({ perms: { net: true } }, async function httpServerWebSocket() {
|
|||
const {
|
||||
response,
|
||||
websocket,
|
||||
} = await Deno.upgradeWebSocket(request);
|
||||
} = Deno.upgradeWebSocket(request);
|
||||
websocket.onerror = () => fail();
|
||||
websocket.onmessage = (m) => {
|
||||
websocket.send(m.data);
|
||||
|
@ -663,6 +663,36 @@ unitTest({ perms: { net: true } }, async function httpServerWebSocket() {
|
|||
await promise;
|
||||
});
|
||||
|
||||
unitTest(function httpUpgradeWebSocket() {
|
||||
const request = new Request("https://deno.land/", {
|
||||
headers: {
|
||||
connection: "Upgrade",
|
||||
upgrade: "websocket",
|
||||
"sec-websocket-key": "dGhlIHNhbXBsZSBub25jZQ==",
|
||||
},
|
||||
});
|
||||
const { response } = Deno.upgradeWebSocket(request);
|
||||
assertEquals(response.status, 101);
|
||||
assertEquals(response.headers.get("connection"), "Upgrade");
|
||||
assertEquals(response.headers.get("upgrade"), "websocket");
|
||||
assertEquals(
|
||||
response.headers.get("sec-websocket-accept"),
|
||||
"s3pPLMBiTxaQ9kYGzzhZRbK+xOo=",
|
||||
);
|
||||
});
|
||||
|
||||
unitTest(function httpUpgradeWebSocketLowercaseUpgradeHeader() {
|
||||
const request = new Request("https://deno.land/", {
|
||||
headers: {
|
||||
connection: "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 });
|
||||
|
|
|
@ -321,7 +321,7 @@
|
|||
);
|
||||
}
|
||||
|
||||
if (request.headers.get("connection") !== "Upgrade") {
|
||||
if (request.headers.get("connection")?.toLowerCase() !== "upgrade") {
|
||||
throw new TypeError(
|
||||
"Invalid Header: 'connection' header must be 'Upgrade'",
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue