BaseHTTPMiddleware structure and StreamingResponse() #2801
Unanswered
usama-elm
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello the Starlette community.
A few weeks back I built a FastAPI Middleware for caching responses using decorators and such (please hold and keep reading, it is relevant I promise it).
FastAPI in many areas being a mere Starlette wrapper I had to contend with reading and building code atop Starlette and not FastAPI really. As the code is somewhat late in versions I built the working code, and then when we updated Starlette as the necessarydependance I noticed something interesting in Starlette's recent codebase changes, specifically in the middleware.base file. There's a new _StreamingResponse type alongside the existing StreamingResponse. This caught my attention because it broke my Response detection and caching mechanism.
Old code:
New working code:
In fact I could drop the whole StreamingResponse() and just use the new one but I kept both for compatibility.
I wanted to understand the changed, why did the Response and why the duplication of code, wouldn't just inheriting from Response avoid this duplication of code, am I missing a piece of context or the inheritance structure could be improved ?
There has already been a discussion around it #2731 and d771bb7#r146823236 but remains unanswered.
Beta Was this translation helpful? Give feedback.
All reactions