【发布时间】:2013-06-02 18:43:53
【问题描述】:
我的 tornado 应用程序中对处理程序的每个请求都需要在处理请求之前检查和验证密钥。 如何在 Tornado 中创建一个中间件类,在处理请求之前检查和验证密钥?
我的中间件类函数看起来像这样。
class Checker(object):
def process_request(self, request):
try:
key = request.META['HTTP_X_KEY']
except KeyError:
key = None
if key and key == os.environ.get('KEY'):
#Process the request
return None
#Redirect to Home Page
return HttpResponsePermanentRedirect('http://google.com', status=301)
【问题讨论】:
标签: python-2.7 tornado middleware