Skip to content

Commit

Permalink
fix(http/ws): case insensitive connection header (denoland#11489)
Browse files Browse the repository at this point in the history
The "connection" header should be case insensitive:
https://datatracker.ietf.org/doc/html/rfc7230#section-6.1
  • Loading branch information
lucacasonato committed Jul 22, 2021
1 parent 4861b13 commit 8b34f07
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
32 changes: 31 additions & 1 deletion cli/tests/unit/http_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 });
Expand Down
2 changes: 1 addition & 1 deletion extensions/http/01_http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
);
Expand Down

0 comments on commit 8b34f07

Please sign in to comment.