def make_redir_response(self, url, headers=None): if not headers: headers = [] if self.extra_headers: for name, value in self.extra_headers.iteritems(): headers.append((name, value)) return WbResponse.redir_response(url, headers=headers)
def make_redir_response(self, url, headers=None): if not headers: headers = [] if self.extra_headers: for name, value in self.extra_headers.iteritems(): headers.append((name, value)) return WbResponse.redir_response(url, headers=headers)
def __call__(self, env, routes): referrer = env.get('HTTP_REFERER') # ensure there is a referrer if referrer is None: return None # get referrer path name ref_split = urlparse.urlsplit(referrer) # ensure referrer starts with one of allowed hosts if not any (referrer.startswith(i) for i in self.match_prefixs): if ref_split.netloc != env.get('HTTP_HOST'): return None path = ref_split.path app_path = env['SCRIPT_NAME'] if app_path: # must start with current app name, if not root if not path.startswith(app_path): return None path = path[len(app_path):] for route in routes: ref_request = route.parse_request(env, False, request_uri = path) if ref_request: break # must have matched one of the routes if not ref_request: return None # must have a rewriter if not ref_request.urlrewriter: return None rewriter = ref_request.urlrewriter rel_request_uri = env['REL_REQUEST_URI'] timestamp_path = '/' + rewriter.wburl.timestamp + '/' # check if timestamp is already part of the path if rel_request_uri.startswith(timestamp_path): # remove timestamp but leave / to make host relative url # 2013/path.html -> /path.html rel_request_uri = rel_request_uri[len(timestamp_path) - 1:] final_url = urlparse.urlunsplit((ref_split.scheme, ref_split.netloc, rewriter.rewrite(rel_request_uri), '', '')) return WbResponse.redir_response(final_url)
def __call__(self, wbrequest): if wbrequest.referrer is None: return None if not any (wbrequest.referrer.startswith(i) for i in self.match_prefixs): return None try: ref_split = urlparse.urlsplit(wbrequest.referrer) path = ref_split.path script_name = wbrequest.env['SCRIPT_NAME'] if not path.startswith(script_name): return None ref_path = path[len(script_name) + 1:].split('/', 1) # No match on any exception try: rewriter = UrlRewriter(ref_path[1], script_name + '/' + ref_path[0] + '/') except Exception: return None rel_request_uri = wbrequest.request_uri[1:] #ref_wb_url = archiveurl('/' + ref_path[1]) #ref_wb_url.url = urlparse.urljoin(ref_wb_url.url, wbrequest.request_uri[1:]) #ref_wb_url.url = ref_wb_url.url.replace('../', '') #final_url = urlparse.urlunsplit((ref_split.scheme, ref_split.netloc, ref_path[0] + str(ref_wb_url), '', '')) final_url = urlparse.urlunsplit((ref_split.scheme, ref_split.netloc, rewriter.rewrite(rel_request_uri), '', '')) except Exception as e: raise e return WbResponse.redir_response(final_url)
def __call__(self, env, the_router): referrer = env.get('HTTP_REFERER') routes = the_router.routes # ensure there is a referrer if referrer is None: return None # get referrer path name ref_split = urlparse.urlsplit(referrer) # require that referrer starts with current Host, if any curr_host = env.get('HTTP_HOST') if curr_host and curr_host != ref_split.netloc: return None path = ref_split.path app_path = env.get('SCRIPT_NAME', '') if app_path: # must start with current app name, if not root if not path.startswith(app_path): return None path = path[len(app_path):] ref_route = None ref_request = None for route in routes: matcher, coll = route.is_handling(path) if matcher: ref_request = the_router.parse_request(route, env, matcher, coll, path) ref_route = route break # must have matched one of the routes with a urlrewriter if not ref_request or not ref_request.urlrewriter: return None rewriter = ref_request.urlrewriter rel_request_uri = env['REL_REQUEST_URI'] timestamp_path = '/' + rewriter.wburl.timestamp + '/' # check if timestamp is already part of the path if rel_request_uri.startswith(timestamp_path): # remove timestamp but leave / to make host relative url # 2013/path.html -> /path.html rel_request_uri = rel_request_uri[len(timestamp_path) - 1:] rewritten_url = rewriter.rewrite(rel_request_uri) # if post, can't redirect as that would lost the post data # (can't use 307 because FF will show confirmation warning) if ref_request.method == 'POST': new_wb_url = WbUrl(rewritten_url[len(rewriter.prefix):]) ref_request.wb_url.url = new_wb_url.url return ref_route.handler(ref_request) final_url = urlparse.urlunsplit((ref_split.scheme, ref_split.netloc, rewritten_url, '', '')) return WbResponse.redir_response(final_url, status='302 Temp Redirect')
def __call__(self, env, the_router): referrer = env.get('HTTP_REFERER') routes = the_router.routes # ensure there is a referrer if referrer is None: return None # get referrer path name ref_split = urlparse.urlsplit(referrer) # require that referrer starts with current Host, if any curr_host = env.get('HTTP_HOST') if curr_host and curr_host != ref_split.netloc: return None path = ref_split.path app_path = env.get('SCRIPT_NAME', '') if app_path: # must start with current app name, if not root if not path.startswith(app_path): return None path = path[len(app_path):] ref_route = None ref_request = None for route in routes: matcher, coll = route.is_handling(path) if matcher: ref_request = the_router.parse_request(route, env, matcher, coll, path) ref_route = route break # must have matched one of the routes with a urlrewriter if not ref_request or not ref_request.urlrewriter: return None rewriter = ref_request.urlrewriter rel_request_uri = env['REL_REQUEST_URI'] timestamp_path = '/' + rewriter.wburl.timestamp + '/' # check if timestamp is already part of the path if rel_request_uri.startswith(timestamp_path): # remove timestamp but leave / to make host relative url # 2013/path.html -> /path.html rel_request_uri = rel_request_uri[len(timestamp_path) - 1:] rewritten_url = rewriter.rewrite(rel_request_uri) # if post, can't redirect as that would lost the post data # (can't use 307 because FF will show confirmation warning) if ref_request.method == 'POST': new_wb_url = WbUrl(rewritten_url[len(rewriter.prefix):]) ref_request.wb_url.url = new_wb_url.url return ref_route.handler(ref_request) final_url = urlparse.urlunsplit((ref_split.scheme, ref_split.netloc, rewritten_url, '', '')) return WbResponse.redir_response(final_url, status='302 Temp Redirect')