From 4af21972a90c0642f49e8aaea106a8975f73a568 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sun, 1 Aug 2021 17:01:52 +0200 Subject: [PATCH] Add ProxyHeadersMiddleware to parse X-Forwarded-Proto header Starlett will automatically generate redirects to add or remove trailing slashes as appropriate. To do this it needs to know the protocol, however. This is usually passed by the proxy in the X-Forwarded-Proto header. --- main.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.py b/main.py index 292f4fc..7aee9d5 100755 --- a/main.py +++ b/main.py @@ -1,6 +1,11 @@ from fastapi import FastAPI +from uvicorn.middleware.proxy_headers import ProxyHeadersMiddleware app = FastAPI() +app.add_middleware( + ProxyHeadersMiddleware, trusted_hosts=[None] +) + @app.get("/f1") async def f1(): return {