minicorn 1.1.1
minicorn 1.1.1 - WebSocket Support
A feature patch adding full WebSocket (RFC 6455) support to the ASGI server, enabling real-time bidirectional communication.
New Features
- WebSocket Protocol (RFC 6455) - Full implementation of the WebSocket protocol on top of the ASGI server
- Automatic Upgrade Detection - Server detects WebSocket upgrade requests and seamlessly switches from HTTP to WS
- WebSocket Handshake - Complete Sec-WebSocket-Key/Accept handshake with proper SHA-1 + Base64 computation
- Frame Parsing - Full binary frame parser supporting:
- Text frames (opcode
0x01) - Binary frames (opcode
0x02) - Continuation frames (opcode
0x00) for fragmented messages - Control frames: Ping (
0x09), Pong (0x0A), Close (0x08)
- Text frames (opcode
- Client Masking - Proper XOR unmasking of client-to-server frames per RFC 6455
- ASGI WebSocket Events - Full ASGI WebSocket lifecycle:
websocket.connect- Connection initiatedwebsocket.receive- Message received (text or binary)websocket.send- Send message to clientwebsocket.disconnect- Connection closedwebsocket.accept- Accept the connection (101 Switching Protocols)websocket.close- Server-initiated close with status code
- Close Code Support - Proper close frame handling with RFC 6455 status codes (1000, 1001, 1002, etc.)
- Max Message Size - Configurable limit (default 16 MB) to prevent memory exhaustion
Bug Fixes
- Connection Timeouts - Improved timeout handling for long-lived connections
Quick Start (WebSocket)
# FastAPI WebSocket example
from fastapi import FastAPI, WebSocket
app = FastAPI()
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
while True:
data = await websocket.receive_text()
await websocket.send_text(f"Echo: {data}")minicorn main:app --asgiNotes
- WebSocket support works on the same port as HTTP - no separate configuration needed
- Compatible with any ASGI framework's WebSocket implementation (FastAPI, Starlette, etc.)
- The WSGI server (synchronous) is unaffected by this change