How to server HTTP/2 protocol with Django

Hi everyone,

I want to create a race condition lab with Django and I need HTTP/2 to reach my views. Because of this, I am using Daphne as my ASGI server. How can I check if my requests are using HTTP/2 or not?

The request.scope dict has keys ‘type’, ‘http_version’ and ‘scheme’ that you can use.

My test program shows that I get {'type': 'http', 'http_version': '2', 'scheme': 'https', ... as the values in that dict.

(See HTTP & WebSocket ASGI Message Format — ASGI 3.0 documentation for more details. Also see GitHub - django/daphne: Django Channels HTTP/WebSocket server)

Thank you for asking this question! I learned a lot researching it.

1 Like