[docs]classRemoteProbeSettings(Configurable):""" A ``HttpProbe`` is a health check that can be used to check the health of a remote's endpoints. It is used as the configuration parser for ``proxy.endpoints[].remote.probe`` settings. .. code-block:: yaml type: http method: GET path: /health headers: x-purpose: "health probe" timeout: 5.0 """method:str="GET"path:str="/"headers:dict[str,Secret]=Field(default_factory=dict)interval:float=10.0timeout:float=10.0verify:bool=True
[docs]classRemoteProbe(Stateful[RemoteProbeSettings]):"""Stateful version of a probe definition."""
def_get_headers(self,url:str)->dict:"""Probe headers, with the endpoint credentials as a Basic fallback (never in the url, so never logged)."""headers={name:value.get_secret_value()forname,valueinself.settings.headers.items()}parsed_url=urlparse(url)ifparsed_url.usernameisnotNoneand"authorization"notin{name.lower()fornameinheaders}:credentials=f"{unquote(parsed_url.username)}:{unquote(parsed_url.passwordor'')}"headers["Authorization"]="Basic "+b64encode(credentials.encode()).decode()returnheaders