【问题标题】:How to add http headers in WSGI middleware?如何在 WSGI 中间件中添加 http 标头?
【发布时间】:2010-10-04 21:05:46
【问题描述】:

如何在 WSGI 中间件中添加 http 标头?

【问题讨论】:

    标签: python wsgi


    【解决方案1】:

    我从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)
    

    诀窍是使用嵌套方法。

    【讨论】:

      猜你喜欢
      • 2018-07-03
      • 1970-01-01
      • 1970-01-01
      • 2016-01-30
      • 1970-01-01
      • 2019-01-30
      • 2012-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多