From 98ca09b6813d16d382bb55b1e5ac858d574f2f75 Mon Sep 17 00:00:00 2001 From: Joe Kaufeld Date: Tue, 29 Oct 2024 23:30:26 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20add=20type=20hints=20an?= =?UTF-8?q?d=20docstring=20updates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spiderweb/middleware/base.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spiderweb/middleware/base.py b/spiderweb/middleware/base.py index e9a22ff..4c1dabf 100644 --- a/spiderweb/middleware/base.py +++ b/spiderweb/middleware/base.py @@ -1,6 +1,11 @@ +from typing import TYPE_CHECKING + from spiderweb.request import Request from spiderweb.response import HttpResponse +if TYPE_CHECKING: + from spiderweb.server_checks import ServerCheck + class SpiderwebMiddleware: """ @@ -22,6 +27,10 @@ class SpiderwebMiddleware: def __init__(self, server): self.server = server + # If there are any startup checks that need to be run, they should be added + # to this list. These checks should be classes that inherit from + # spiderweb.server_checks.ServerCheck. + self.checks: list[ServerCheck] = [] def process_request(self, request: Request) -> HttpResponse | None: # This method is called before the request is passed to the view. You can safely @@ -45,5 +54,6 @@ class SpiderwebMiddleware: self, request: Request, response: HttpResponse, rendered_response: str ) -> str: # This method is called after all the middleware has been processed and receives - # the final rendered response in str form. You can modify the response here. + # the final rendered response in str form. You can modify the response here. This + # method *must* return a str version of the rendered response. return rendered_response