I am using FastAPI for building an application.
I have the place where i set some custom response headers.
There is the standard example from FastAPI docs
from fastapi import FastAPI, Response
app = FastAPI()
@app.get("/headers-and-object/")
def get_headers(response: Response):
response.headers["X-Cat-Dog"] = "alone in the world"
return {"message": "Hello World"}
fastapi dev test.py --host 0.0.0.0 --port 8080
When i call this, my custom header is converted to lower case (the name of the header)
curl -i "http://0.0.0.0:8080/headers-and-object/"
HTTP/1.1 200 OK
date: Fri, 08 Nov 2024 11:43:54 GMT
server: uvicorn
content-length: 25
content-type: application/json
x-cat-dog: alone in the world
{"message":"Hello World"}
The header is “x-cat-dog” but i need it to be same as i returned “X-Cat-Dog”
is there a way to disable this behavior and have a header “as it was returned”?
I have no option to live with lower case headers. I have some JS application that reads responses and that app can not be modified and it expects a header is as. It can not find a lower case header.
Are there options?