modpython.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:nav 作者: UNINETT 项目源码 文件源码
def headerparserhandler(req):
    """A mod_python headerparserhandler to authenticate and authorize a request
    using NAV.

    It uses NAV's Django authenticaton and authorization middlewares and
    translates between mod_python and Django requests/responses.

    """
    from mod_python import apache

    req.get_full_path = lambda: req.unparsed_uri
    is_ajax = req.headers_in.get('X-Requested-With', '') == 'XMLHttpRequest'
    req.is_ajax = lambda: is_ajax
    req.COOKIES = _get_cookie_dict(req)

    for mware in (SessionMiddleware, AuthenticationMiddleware,
                  AuthorizationMiddleware):
        response = mware().process_request(req)

    try:
        if response:
            if 'Location' in response:
                req.headers_out['Location'] = response['Location']
            return response.status_code
        else:
            return apache.OK
    finally:
        # ensure we don't leak database connections. it's inefficient, yes, but
        # that's the price you pay for authorizing access to your other crap
        connection.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号