Exemple #1
0
def call_view(req, path):
    """ Selects a function with a matching RegEx and executes it. """
    response = Response(content='404 - Not Found', status_code=404)
    for regex, view in views.items():
        match = regex.match(path)
        if match:
            csp = {}
            try:
                response = wrap_response(view['function'](req, *match.groups()))
                if 'csp' in view:
                    csp = view['csp']
            except HttpError as e:
                response = e.build_response()
            except Exception as e:
                response = Http500Error().build_response()
                logging.getLogger(__name__).exception(e)
            response.set_header('Content-Security-Policy',
                                lib.csp.generate_policy(csp))
            break
    return response
Exemple #2
0
 def build_response(self):
     r = Response(content=self.message, status_code=401)
     r.set_header('WWW-Authenticate', 'Basic realm="%s"' % self.realm)
     return r