starlette
starlette copied to clipboard
pathsend causing issues with BaseHTTPMiddleware
Hi guys
This is a follow up of https://github.com/emmett-framework/granian/issues/320
I'm not entirely sure if this is really a bug of starlette, or more of a feature that's missing or so.
On my staging environment, I did receive an assertion error:
File "/tmp/8dc89326e92b51b/antenv/lib/python3.12/site-packages/starlette/middleware/base.py", line 173, in body_stream
2024-06-10T09:58:53.052818649Z assert message["type"] == "http.response.body"
As I could not reproduce it locally, I monkey-patched starlette and printed an error message with details:
2024-06-10T09:58:53.052814649Z File "/tmp/8dc89326e92b51b/antenv/lib/python3.12/site-packages/starlette/middleware/base.py", line 173, in body_stream
2024-06-10T09:58:53.052818649Z assert message["type"] == "http.response.body", f"Unexpected message of type {message['type']} from class {type(self)}: {message}" # noqa: E501
2024-06-10T09:58:53.052821649Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-06-10T09:58:53.052824449Z AssertionError: Unexpected message of type http.response.pathsend from class <class 'starlette.middleware.base.BaseHTTPMiddleware'>: {'type': 'http.response.pathsend', 'path': 'frontend_app/output/index.html'}
I think this happens because my server does support the pathsend extension, however middlware that act's on it and just derives from BaseHTTPMiddleware will fail, since it cannot handle this.
[!IMPORTANT]
- We're using Polar.sh so you can upvote and help fund this issue.
- We receive the funding once the issue is completed & confirmed by you.
- Thank you in advance for helping prioritize & fund our backlog.