This commit is contained in:
2024-12-17 14:36:15 -08:00
parent b2dbf46d28
commit 06d106de53
17731 changed files with 3037186 additions and 144 deletions

View File

@@ -0,0 +1,26 @@
class BaseMiddleware:
"""
Base class for implementing ASGI middleware. Inherit from this and
override the setup() method if you want to do things before you
get to.
Note that subclasses of this are not self-safe; don't store state on
the instance, as it serves multiple application instances. Instead, use
scope.
"""
def __init__(self, inner):
"""
Middleware constructor - just takes inner application.
"""
self.inner = inner
async def __call__(self, scope, receive, send):
"""
ASGI application; can insert things into the scope and run asynchronous
code.
"""
# Copy scope to stop changes going upstream
scope = dict(scope)
# Run the inner application along with the scope
return await self.inner(scope, receive, send)