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:
@@ -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"],
|
||||
],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user