如何在 WSGI 中间件中添加 http 标头? [英] How to add http headers in WSGI middleware?
本文介绍了如何在 WSGI 中间件中添加 http 标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 WSGI 中间件中添加 http 标头?
How can http headers be added within a WSGI middleware?
推荐答案
我从 塔书.
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)
诀窍是使用嵌套方法.
这篇关于如何在 WSGI 中间件中添加 http 标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文