9
Làm cách nào để thêm tiêu đề http trong phần mềm trung gian WSGI?Cách thêm tiêu đề http vào phần mềm trung gian WSGI?
Làm cách nào để thêm tiêu đề http trong phần mềm trung gian WSGI?Cách thêm tiêu đề http vào phần mềm trung gian WSGI?
Tôi đã tìm thấy một ví dụ hay từ pylons book.
class Middleware(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
def custom_start_response(status, headers, exc_info=None):
headers.append(('Set-Cookie', "name=value"))
return start_response(status, headers, exc_info)
return self.app(environ, custom_start_response)
Bí quyết là sử dụng phương pháp lồng nhau.