Into an HTTPS context, our application (a fastapi) launched through uvicorn and the python3_raw_asgi template doesn't know that the protocol used by the client is HTTPS.
It causes redirections to HTTP instead of HTTPs because the fastapi has a redirection mechanism (http 307) for URLs with or without trailing slashes.
--forwarded-allow-ips TEXT Comma separated list of IPs to trust with
proxy headers. Defaults to the
$FORWARDED_ALLOW_IPS environment variable if
available, or '127.0.0.1'.
Problem
Into an HTTPS context, our application (a fastapi) launched through uvicorn and the python3_raw_asgi template doesn't know that the protocol used by the client is HTTPS. It causes redirections to HTTP instead of HTTPs because the fastapi has a redirection mechanism (http 307) for URLs with or without trailing slashes.
Sources: https://github.com/tiangolo/fastapi/discussions/9328#discussioncomment-8242245 https://www.uvicorn.org/deployment/#running-behind-nginx
Uvicorn provided options to handle this:
Solution
Always forward HTTP headers through uvicorn.
Before:
After:
Tested succesfully in my HTTPS context.
We can also decide that it is the responsibility of the developer to add these options. So this ticket can be used as a basis of knowledge.