Skip to content

pathsend causing issues with BaseHTTPMiddleware #2613

@aersam

Description

@aersam

Hi guys

This is a follow up of emmett-framework/granian#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.
Fund with Polar

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions