feat: add first-class WebSocket support via ctx.upgrade() and app.ws() (#3774)

## Summary

- **`ctx.upgrade()`** on the `Context` class with two overloads:
- **Bare mode**: `ctx.upgrade()` or `ctx.upgrade(options)` returns `{
socket, response }` for manual event wiring
- **Managed mode**: `ctx.upgrade(handlers)` accepts `{ open, message,
close, error }` and returns the upgrade `Response` directly
- **`app.ws(path, handlers, options?)`** shorthand that registers a GET
route with automatic WebSocket upgrade (managed mode only)
- Both support `idleTimeout` and `protocol` options forwarded to
`Deno.upgradeWebSocket()`
- Throws `HttpError(400)` on non-WebSocket requests
- Case-insensitive `Upgrade` header check per RFC 6455 §4.2.1
- Exports `WebSocketHandlers` and `WebSocketUpgradeOptions` types from
`fresh`
- Full documentation page with examples for managed mode, bare mode,
broadcast chat, and client-side usage
This commit is contained in:
Bartek Iwańczuk
2026-04-22 19:17:43 +02:00
committed by GitHub
parent 49c4be1ac6
commit 0ab5a2ab28
8 changed files with 605 additions and 25 deletions
+1
View File
@@ -107,6 +107,7 @@ const toc: RawTableOfContents = {
],
["active-links", "Active links", "link:latest"],
["session-management", "Session management", "link:latest"],
["websockets", "WebSockets", "link:latest"],
["common-patterns", "Common Patterns", "link:latest"],
],
},