如何在WSGI中间件中添加HTTP头?
如何在WSGI中间件中添加HTTP头信息?
1 个回答
21
我找到了一段很不错的例子,来自于pylons书籍。
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)
这里的窍门是使用嵌套的方法。