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.
This commit is contained in:
Peter J. Holzer 2021-08-01 17:01:52 +02:00
parent 5ddf0bc9c5
commit 4af21972a9
1 changed files with 5 additions and 0 deletions

View File

@ -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 {