X-Massge Header Problem #11760
Replies: 2 comments
-
Hi @Partymann2000 , To put it simply, the 303 response you received from your delete request does include the header you specified. However, the browser will not carry over this request header when redirecting to The alternative is to pass information using query parameters: ...
else:
x_message = "Channel erfolgreich gelöscht"
response = RedirectResponse(url=f"/server/{guild_id}/modules/youtube?x_message={x_message}", status_code=303)
print(response.headers)
return response
@app.get("/redirect-to-api")
async def redirect_to_target(x_message: str | None = None):
return {"message": "You have been redirected.", "header": x_message} |
Beta Was this translation helpful? Give feedback.
-
If, and only if you can have some control over who is calling your api, then you can stop following redirects: @app.get("/redirect")
async def redirect():
return {"hello": "redirect"}
@app.get("/")
async def will_redirect():
x_message = "Channel erfolgreich gelöscht"
headers = {"X-Message": x_message}
return RedirectResponse(url="http://localhost:8000/redirect", headers=headers, status_code=303) And then you disable redirects: import requests
r = requests.get("http://localhost:8000", allow_redirects=False)
print(f"Got my headers {r.headers}, now will follow redirect to {r.headers['Location']}")
r = requests.get(r.headers["Location"])
print(r.json()) |
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
Description
I would like to add an X-Massge, but only None is displayed as the value
Operating System
Windows
Operating System Details
No response
FastAPI Version
latest
Pydantic Version
latest
Python Version
3.12
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions