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()
评论列表
文章目录