3
미들웨어의 내부 레이어가 start_response
을 호출하여 반환하는 HTTP 상태 (예 : 200 OK
)를 캡처해야하는 WSGI 미들웨어가 있습니다. 현재 나는 다음과 같은 일을 해요,하지만 목록을 남용하는 것은 나에게 "오른쪽"솔루션이 될 것 같지 않습니다WSGI start_response를 가로채는 적절한 방법은 무엇입니까?
class TransactionalMiddlewareInterface(object): def __init__(self, application, **config): self.application = application self.config = config def __call__(self, environ, start_response): status = [] def local_start(stat_str, headers=[]): status.append(int(stat_str.split(' ')[0])) return start_response(stat_str, headers) try: result = self.application(environ, local_start) finally: status = status[0] if status else 0 if status > 199 and status
목록 남용하는 이유는 나는에 새로운 값을 할당 할 수 있다는 것입니다 부모 이름 공간.
정말 멋진 솔루션입니다. 고맙습니다. – amcgregor