π§ HTTP/2 and HTTPSΒΆ
Leveraging HTTP/2ΒΆ
HTTP/2 is the new protocol for the web and it is a better and optimum solution
for fast webservers.
Duck supports HTTP/2 using the h2 Python package, enabling faster and more efficient communication compared to HTTP/1.1.
With features like multiplexing, header compression, and lower latency, HTTP/2 significantly improves performance.
Warning
It is strongly recommended to use HTTP/2 only over a secure HTTPS connection. Running HTTP/2 over an unencrypted connection (h2c) in production may expose your data to security risks.
Getting StartedΒΆ
To enable HTTP/2 in Duck, simply set the following in your configuration:
HTTP_2_SUPPORT = True
Switching to HTTP/2ΒΆ
There are two ways to enable HTTP/2 in your Duck web app:
Enable HTTPS by setting:
ENABLE_HTTPS = True
This ensures secure communication and automatically enables HTTP/2 support.
Send an Upgrade Header to Duck:
Upgrade: h2c
This allows HTTP/1.1 clients to request an upgrade to h2c (HTTP/2 over cleartext).
By using either of these methods, Duck will seamlessly switch to HTTP/2, improving speed, efficiency, and overall performance. ππ₯
Enabling HTTPSΒΆ
To activate HTTPS, set the following in your settings.py:
ENABLE_HTTPS = True
Force HTTPS RedirectionΒΆ
To automatically redirect all HTTP traffic to HTTPS, enable the redirect feature:
FORCE_HTTPS = True
Note
FORCE_HTTPS requires ENABLE_HTTPS to be set to True.
Local SSL Certificate GenerationΒΆ
Duck includes an ssl-gen command to generate self-signed SSL certificates.
RequirementsΒΆ
Ensure you have OpenSSL installed before running the command.
Production RecommendationsΒΆ
Use port 80 for HTTP and port 443 for HTTPS in production.
Secure your SSL configuration for enhanced security.