Openstack Swift学习(四):中间件

栏目: 编程工具 · 发布时间: 7年前

内容简介:假设要添加一个名为 demomiddleware 的中间件在 swift/swift/common/middleware 下新建 demomiddleware.py,内容如下:在 /etc/swift/proxy-server.conf 中添加中间件,在 [pipeline:main] 部分添加 demomiddleware, 并添加 [filter:demomiddleware] 部分。如下所示:

假设要添加一个名为 demomiddleware 的中间件

在 swift/swift/common/middleware 下新建 demomiddleware.py,内容如下:

from swift.common.swob import Request, Response
class DemoMiddleware(object):
    def __init__(self,app,conf):
        self.app = app
        print('init demo middleware')
    def __call__(self, env, start_response):
        print('request method:'+env['REQUEST_METHOD'])
        print('do nothing in demo middleware')
        return self.app(env, start_response)

def demomiddleware_factory(global_conf, **local_conf):
    conf = global_conf.copy()
    conf.update(local_conf)
    def demomiddleware_filter(app):
        return DemoMiddleware(app, conf)
    return demomiddleware_filter

在 /etc/swift/proxy-server.conf 中添加中间件,在 [pipeline:main] 部分添加 demomiddleware, 并添加 [filter:demomiddleware] 部分。如下所示:

[pipeline:main]
pipeline = healthcheck cache tempauth proxy-logging demomiddleware proxy-server

[filter:demomiddleware]
paste.filter_factory = swift.common.middleware.demomiddleware:demomiddleware_factory

重启 proxy server


以上所述就是小编给大家介绍的《Openstack Swift学习(四):中间件》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Build Your Own Web Site the Right Way Using HTML & CSS

Build Your Own Web Site the Right Way Using HTML & CSS

Ian Lloyd / SitePoint / 2006-05-02 / USD 29.95

Build Your Own Website The Right Way Using HTML & CSS teaches web development from scratch, without assuming any previous knowledge of HTML, CSS or web development techniques. This book introduces you......一起来看看 《Build Your Own Web Site the Right Way Using HTML & CSS》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具