Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(std/ws): protocol & version support #8505

Merged
merged 6 commits into from
Nov 26, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added sec-websocket-version and made both optional
  • Loading branch information
Industrial committed Jun 7, 2020
commit 6df1a0aec7367c745dba0a74ec48d24c5dc08eab
22 changes: 13 additions & 9 deletions std/ws/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,19 +429,23 @@ export async function acceptWebSocket(req: {
if (typeof secKey !== "string") {
throw new Error("sec-websocket-key is not provided");
}
const secAccept = createSecAccept(secKey);
const newHeaders = new Headers({
Upgrade: "websocket",
Connection: "Upgrade",
"Sec-WebSocket-Accept": secAccept,
});
const secProtocol = headers.get("sec-websocket-protocol");
if (typeof secProtocol !== "string") {
throw new Error("sec-websocket-protocol is not provided");
if (typeof secProtocol === "string") {
newHeaders.set("Sec-WebSocket-Protocol", secProtocol);
}
const secVersion = headers.get("sec-websocket-version");
if (typeof secVersion === "string") {
newHeaders.set("Sec-WebSocket-Version", secVersion);
}
const secAccept = createSecAccept(secKey);
await writeResponse(bufWriter, {
status: 101,
headers: new Headers({
Upgrade: "websocket",
Connection: "Upgrade",
"Sec-WebSocket-Accept": secAccept,
"Sec-WebSocket-Protocol": secProtocol,
}),
headers: newHeaders,
});
return sock;
}
Expand Down