Overview

Daphne 4.0, released on August 1, 2023, adds HTTP/2 support and improves WebSocket performance.

Main Features

HTTP/2 support

Daphne now natively supports HTTP/2, enabling request multiplexing and header compression.

python
# Run Daphne with HTTP/2
# daphne -b 0.0.0.0 -p 8000 myproject.asgi:application

# asgi.py
import os
from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
application = get_asgi_application()

Improved WebSocket

WebSocket connection handling is more robust with better cleanup of closed connections and configurable timeouts.

python
# Run with custom WebSocket timeout
# daphne --websocket_timeout 300 myproject.asgi:application

# settings.py
CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels_redis.core.RedisChannelLayer',
        'CONFIG': {'hosts': [('127.0.0.1', 6379)]},
    }
}

Sources