def test_build_url_forward_headers(self): request = DummyRequest() request.environ = { "SERVER_NAME": "example.com" } request.registry.settings = { "checker": { "forward_headers": ["Cookie"] } } request.headers["Cookie"] = "test" self.assertEqual( build_url( "Test", "https://camptocamp.com/toto?titi#tutu", request ), { "url": "https://camptocamp.com/toto?titi#tutu", "headers": { "Cache-Control": "no-cache", "Cookie": "test", } } )
def test_build_url_other(self): self.assertEqual( build_url("Test", "https://camptocamp.com/toto?titi#tutu", self._create_dummy_request()), { "url": "https://camptocamp.com/toto?titi#tutu", "headers": { "Cache-Control": "no-cache", } })
def check(request): params = request.params display = host["display"] if "host" not in params or display == params["host"]: url_headers = build_url( "check_collector", "%s%s/health_check" % (host["url"], c2c_base), request ) r = requests.get(params={"max_level": str(host.get("max_level", max_level))}, **url_headers) r.raise_for_status()
def test_build_url_https(self): self.assertEqual( build_url("Test", "https://example.com/toto?titi#tutu", self._create_dummy_request()), { "url": "http://localhost/toto?titi#tutu", "headers": { "Cache-Control": "no-cache", "Host": "example.com" } })
def check(request): params = request.params display = host["display"] if "host" not in params or display == params["host"]: url_headers = build_url( "check_collector", "%s/%s/health_check" % (host["url"], c2c_base), request) r = requests.get(params={ "max_level": str(host.get("max_level", max_level)) }, **url_headers) r.raise_for_status()
def test_build_url_docker(self): request = DummyRequest() request.registry.settings = { "checker": { "base_internal_url": "http://localhost:8080", } } self.assertEqual( build_url("Test", "/toto?titi#tutu", request), { "url": "http://localhost:8080/toto?titi#tutu", "headers": { "Cache-Control": "no-cache", } })
def test_build_url_other(self): self.assertEqual( build_url( "Test", "https://camptocamp.com/toto?titi#tutu", self._create_dummy_request() ), { "url": "https://camptocamp.com/toto?titi#tutu", "headers": { "Cache-Control": "no-cache", } } )
def test_build_url_https(self): self.assertEqual( build_url( "Test", "https://example.com/toto?titi#tutu", self._create_dummy_request() ), { "url": "http://localhost/toto?titi#tutu", "headers": { "Cache-Control": "no-cache", "Host": "example.com" } } )
def test_build_url_https(self): request = DummyRequest() request.registry.settings = { "checker": { "base_internal_url": "https://localhost", "forward_host": True, } } self.assertEqual( build_url("Test", "/toto?titi#tutu", request), { "url": "https://localhost/toto?titi#tutu", "headers": { "Cache-Control": "no-cache", "Host": "example.com:80" } })
def test_build_url_forward_headers(self): request = DummyRequest() request.registry.settings = { "checker": { "base_internal_url": "http://localhost", "forward_headers": ["Cookie"] } } request.headers["Cookie"] = "test" self.assertEqual( build_url("Test", "/toto?titi#tutu", request), { "url": "http://localhost/toto?titi#tutu", "headers": { "Cache-Control": "no-cache", "Cookie": "test", } })
def test_build_url_forward_headers(self): request = DummyRequest() request.environ = {"SERVER_NAME": "example.com"} request.registry.settings = { "checker": { "forward_headers": ["Cookie"] } } request.headers["Cookie"] = "test" self.assertEqual( build_url("Test", "https://camptocamp.com/toto?titi#tutu", request), { "url": "https://camptocamp.com/toto?titi#tutu", "headers": { "Cache-Control": "no-cache", "Cookie": "test", } })
def __call__(self, request) -> Any: # pylint: disable=inconsistent-return-statements params = request.params display = self.host["display"] if "host" not in params or display == params["host"]: url_headers = build_url( "check_collector", "%s/%s/health_check" % (self.host["url"].rstrip("/"), c2c_base.strip("/")), request, ) r = requests.get( params={ "max_level": str(self.host.get("max_level", max_level)) }, timeout=120, **url_headers, ) r.raise_for_status() return r.json()
def __call__( self, request: pyramid.request.Request ) -> Optional[Dict[str, Any]]: params = request.params display = self.host["display"] if "host" not in params or display == params["host"]: url_headers = build_url( "check_collector", f"{self.host['url'].rstrip('/')}/{c2c_base.strip('/')}/health_check", request, ) r = requests.get( params={ "max_level": str(self.host.get("max_level", max_level)) }, timeout=120, **url_headers, # type: ignore ) r.raise_for_status() return cast(Dict[str, Any], r.json()) return None