How can you add a custom header to EVERY response #14755
Unanswered
fraser-langton
asked this question in
Questions
Replies: 3 comments 1 reply
-
|
Hi! you can also try Custom Request and APIRoute class though you'd still need to catch exceptions. #6376 |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
As far as I know, if you don’t use an |
Beta Was this translation helpful? Give feedback.
0 replies
This comment was marked as spam.
This comment was marked as spam.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
I want to add a header to EVERY response, the fastAPI model doesn't give you a response object in the middleware (in django I would just add to that) so your option is to only catch and exception once and turn into a response, then subsequent middleware won't get an exception, and neither will exception handlers (which run after middleware)
Wondering what the best way to acheive this is, neither feels great as it isn't in a clean simple spot
Operating System
macOS
Operating System Details
No response
FastAPI Version
0.116.2
Pydantic Version
2.11.9
Python Version
Python 3.12.7
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions