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学习(四):中间件》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

PHP for the World Wide Web, Second Edition (Visual QuickStart Gu

PHP for the World Wide Web, Second Edition (Visual QuickStart Gu

Larry Ullman / Peachpit Press / 2004-02-02 / USD 29.99

So you know HTML, even JavaScript, but the idea of learning an actual programming language like PHP terrifies you? Well, stop quaking and get going with this easy task-based guide! Aimed at beginning ......一起来看看 《PHP for the World Wide Web, Second Edition (Visual QuickStart Gu》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

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

HEX CMYK 互转工具