def redirect_tween_factory(handler, registry, redirects=None): if redirects is None: # N.B. If we fail to load or parse the redirects file, the application # will fail to boot. This is deliberate: a missing/corrupt redirects # file should result in a healthcheck failure. with open(resource_filename("h", "redirects"), encoding="utf-8") as fp: redirects = parse_redirects(fp) def redirect_tween(request): url = lookup_redirects(redirects, request) if url is not None: return httpexceptions.HTTPMovedPermanently(location=url) return handler(request) return redirect_tween
def redirect_tween_factory(handler, registry, redirects=None): if redirects is None: # N.B. If we fail to load or parse the redirects file, the application # will fail to boot. This is deliberate: a missing/corrupt redirects # file should result in a healthcheck failure. with open('h/redirects', encoding='utf-8') as fp: redirects = parse_redirects(fp) def redirect_tween(request): url = lookup_redirects(redirects, request) if url is not None: return httpexceptions.HTTPMovedPermanently(location=url) return handler(request) return redirect_tween