def redirect(info: interceptor.Request): url = info.request_url if url.host() == 'www.reddit.com': url.setHost('old.reddit.com') try: info.redirect(url) message.info("Redirecting to " + url.toString()) except RedirectException: pass
def intercept_fn(info: interceptor.Request): url = info.request_url # Work around AWS urls when working on VPN url_host = url.host() if EMR_URL_REGEX.match(url_host): redir_url_host = _aws_dns_to_ip(url_host) url.setHost(redir_url_host) info.redirect(url)
def int_fn(info: interceptor.Request): """Block the given request if necessary.""" if (info.resource_type != interceptor.ResourceType.main_frame or info.request_url.scheme() in {"data", "blob"}): return url = info.request_url redir = REDIRECT_MAP.get(url.host()) if redir is not None and redir(url) is not False: message.info("Redirecting to " + url.toString()) info.redirect(url)
def int_fn(info: interceptor.Request): """Redirect logic.""" url = info.request_url if (info.resource_type != interceptor.ResourceType.main_frame) or ( url.scheme() in {"data", "blob",} ): return host = url.host() if host[:4] == "www.": host = host[4:] redir = REDIRECT_MAP.get(host) if redir is not None and redir(url) is not False: message.info("Redirecting to " + url.toString()) info.redirect(url)