tomwojcik/starlette-context

rewrite middleware to pure ASGI

dmig-alarstudios opened this issue · 5 comments

Since there are issues in Starlette caused by BaseHTTPMiddleware class, this package becomes a source of these issues in any project using it:

The simple solution would be to rewrite the middleware to pure ASGI.

Hmm, good point. I never heard about this issue before and I'm not affected by this. I will definitely rewrite this to pure ASGI at some point as it seems like there are no downsides of the solution you suggest but I will give it some time until the creators of Starlette decide what to do next. From the tickets you linked I conclude that BaseHTTPMiddleware is just broken in some cases.

Not in some cases. It's broken by design.
Problems are: ReadTimeouts, if using BaseHTTPMiddleware-based middleware along with BackgroundTasks and huge memory usage because BaseHTTPMiddleware spools everything in memory.

Yeah, I see. I will rewrite it over the weekend. Thanks for letting me know.

@dmig-alarstudios 0.3.0 published with what should be a functioning "raw" middleware. Let me know if it doesn't work as expected.