Pounce supports permessage-deflate compression (RFC 7692) for WebSocket connections, reducing bandwidth by 60-80% for text messages.
Configuration
Enabled by default, but only negotiated when the client offers
permessage-deflate in Sec-WebSocket-Extensions. Requires wsproto:
pip install bengal-pounce[ws]
from pounce import ServerConfig
config = ServerConfig(
websocket_compression=True, # default
websocket_max_message_size=10_485_760, # 10 MB default
)
To disable (e.g., for already-compressed data):
config = ServerConfig(websocket_compression=False)
How It Works
- Client sends
Sec-WebSocket-Extensions: permessage-deflateduring handshake - Pounce includes the extension in the 101 response only when the offer is present
- Compression/decompression is handled transparently at the protocol layer
Your ASGI app sends and receives uncompressed data -- no code changes needed.
Performance
| Message Type | Uncompressed | Compressed | Savings |
|---|---|---|---|
| JSON (repetitive keys) | 10 KB | 2-3 KB | 70-80% |
| HTML fragments | 5 KB | 1-2 KB | 60-80% |
| Random/binary data | 10 KB | ~10 KB | ~0% |
CPU overhead is < 5% for typical workloads. All modern browsers support permessage-deflate.