您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

25 行
688 B

  1. import falcon
  2. import constants
  3. class RequireCSV(object):
  4. def process_request(self, req, resp):
  5. if req.method in ('POST', 'PUT'):
  6. if constants.MEDIA_CSV not in req.content_type:
  7. raise falcon.HTTPUnsupportedMediaType
  8. class AuthMiddleware(object):
  9. def __init__(self, userAgentRequired):
  10. self._userAgentRequired = userAgentRequired
  11. def process_request(self, req, resp):
  12. authorization = req.get_header('Authorization')
  13. userAgent = req.get_header('User-Agent')
  14. if userAgent != self._userAgentRequired:
  15. if authorization is None: #make clients believe that Authorization header is the issue
  16. raise falcon.HTTPForbidden
  17. else:
  18. raise falcon.HTTPUnauthorized