Overview
Uvicorn 0.14, released on June 1, 2021, adds WebSocket max message size configuration and asyncio streams support for HTTP transport.
Main Features
WebSocket max size
The --ws-max-size parameter limits the size of incoming WebSocket messages, protecting the server against excessively large payloads.
python
# Launch with WebSocket limit at 1 MB
# uvicorn app:app --ws-max-size 1048576
import uvicorn
uvicorn.run(
'app:app',
ws_max_size=1_048_576, # 1 MB
host='0.0.0.0',
port=8000,
)
Asyncio streams
The HTTP transport can use asyncio streams (asyncio.streams), providing an alternative to low-level transport for certain use cases.
python
# Minimal ASGI application
async def app(scope, receive, send):
if scope['type'] == 'http':
await send({'type': 'http.response.start',
'status': 200,
'headers': [[b'content-type', b'text/plain']]})
await send({'type': 'http.response.body',
'body': b'Hello from Uvicorn 0.14'})
