secure
secure copied to clipboard
Server header is not overridden
I am using the following in a FastAPI project
server = secure.Server().set("Secure")
But the result is:
server: uvicorn
server: Secure
ie. it does not override the server header but simply adds another one.
I just got the same problem. Turns out it is uvicorn that injects the server header unconditionally.
You can run uvicorn with the --no-server-header option to disable this header.
Ref: https://www.uvicorn.org/settings/#http
In my case I fixed it now using
uvicorn.run(
app,
host="0.0.0.0",
port=8000,
server_header=False,
)
Thanks @lsmith77 and @nashyeung! I'll add this to the documentation.
I'll just point out in this issue that if you use Uvicorn VIA Gunicorn (eg: as a Uvicorn-Worker), this setting is not passed so it's impossible to override, unless subclassing the worker itself. This is not a problem with Secure.py but with Uvicorn/Gunicorn combo.
Refer here -> https://github.com/encode/uvicorn/issues/1436 | https://github.com/encode/uvicorn/discussions/1435