1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -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:
Luca Casonato 2021-07-22 14:28:55 +02:00 committed by GitHub
parent 4861b13aab
commit 8b34f07bb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 2 deletions

View file

@ -642,7 +642,7 @@ unitTest({ perms: { net: true } }, async function httpServerWebSocket() {
const { const {
response, response,
websocket, websocket,
} = await Deno.upgradeWebSocket(request); } = Deno.upgradeWebSocket(request);
websocket.onerror = () => fail(); websocket.onerror = () => fail();
websocket.onmessage = (m) => { websocket.onmessage = (m) => {
websocket.send(m.data); websocket.send(m.data);
@ -663,6 +663,36 @@ unitTest({ perms: { net: true } }, async function httpServerWebSocket() {
await promise; 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() { 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 });

View file

@ -321,7 +321,7 @@
); );
} }
if (request.headers.get("connection") !== "Upgrade") { if (request.headers.get("connection")?.toLowerCase() !== "upgrade") {
throw new TypeError( throw new TypeError(
"Invalid Header: 'connection' header must be 'Upgrade'", "Invalid Header: 'connection' header must be 'Upgrade'",
); );