Review generated WSGI logging middleware

from WSGI
Python 3.14 advanced 8 min 4 issues to find

Review this generated middleware for protocol correctness, security, edge cases, and streaming behavior.

Log the method, path, and response status while preserving the downstream WSGI response.

Python
class AccessLogMiddleware:
    def __init__(self, app):
        self.app = app
        self.status = None

    def __call__(self, environ, start_response):
        chunks = []
        def capture(status, headers, exc_info=None):
            self.status = status
            return start_response(status, headers, exc_info)

        result = self.app(environ, capture)
        for chunk in result:
            chunks.append(chunk)
        print(environ.get("HTTP_AUTHORIZATION"), self.status)
        return [b"".join(chunks)]

generated code is illustrative, not from any one model

Open in playground
Report an error