def get_url_to_call(self): url_to_call = self.rotation_policy.pick() pre_get_real_url_to_call.send(sender=self, request=self.request, url_to_call=url_to_call) web_call = getattr(requests, self.request.method.lower()) if "@" in url_to_call: # this is a basic AUTH call, mebbe? basic_auth_params = parse_basic_auth(url_to_call) url_to_call = basic_auth_params.get('url', url_to_call) web_call = partial(web_call, auth=(basic_auth_params['login'], basic_auth_params['password'])) self.analytics.increment("proxy.%s.dispatch.server.get_url" % (self.cfg.get('name').lower(), )) #TODO the regex matcher/resolver is a bit of a hack, it only works for one match ($1) - we should make this legit if len(self.request.resolver_match.args) > 0: matched = self.request.resolver_match.args[0] url_to_call = url_to_call.replace("$1", matched) self.web_call = web_call self.url_to_call = url_to_call post_get_real_url_to_call.send(sender=self, request=self.request, url_to_call=url_to_call, web_call=web_call) return web_call, url_to_call
def healthcheck(self, server=None, **kwargs): if server is None: server = convert_variable_to_env_setting(self.server) try: basic_auth_params = parse_basic_auth(server) if "login" in basic_auth_params: resp = requests.head(server, auth=(basic_auth_params['login'], basic_auth_params['password'])) else: resp = requests.head(server) if resp.ok: return HealthCheckResponse(server=server, name=self.name) else: health_check_response = HealthCheckResponse(name=self.name, server=server, code=resp.status_code, passed=False) return health_check_response except ConnectionError as e: health_check_response = HealthCheckResponse(code=999, passed=False) health_check_response.descriptive_message = "Connection Refused" health_check_response.technical_message = "connection refused" health_check_response.server = server health_check_response.name = self.name return health_check_response