def dispatch(self, request, path, *args, **kwargs): """ The parent implementation is to proxy the request and return it from the upstream server.""" # with container(self.get_object()): response = None with container(self.get_object()), statsd.timer('proxy_wait'): self.upstream = self.base_url for _ in range(15): try: if path and path[0] == "/": path = path[1:] response = super(DynProxyView, self).dispatch(request, path) if "location" in response._headers: response._headers["location"] = rewrite_redirect( response, request) break except: time.sleep(1) self.get_object().cleanup() if not response: return HttpResponse( "Your app failed to boot, perhaps there is a syntax error in your code." ) return response
def test_rewrite_redirect(): response = FakeObject() response._headers = {"location": ('Location', "http://localhost:9000/hello")} request = FakeObject() def uri(): return "http://localhost:9000/12/result//asd" request.build_absolute_uri = uri expected = ('Location', "http://localhost:9000/12/result//hello/") result = rewrite_redirect(response, request) assert expected == result
def dispatch(self, request, path, *args, **kwargs): """ The parent implementation is to proxy the request and return it from the upstream server.""" # with container(self.get_object()): response = None with container(self.get_object()),statsd.timer('proxy_wait'): self.upstream = self.base_url for _ in range(15): try: if path and path[0] == "/": path = path[1:] response = super(DynProxyView, self).dispatch(request, path) if "location" in response._headers: response._headers["location"] = rewrite_redirect(response, request) break except: time.sleep(1) self.get_object().cleanup() if not response: return HttpResponse( "Your app failed to boot, perhaps there is a syntax error in your code.") return response