HTTP client API¶
client
¶
Call Gluetun and fetch PIA endpoints without exposing connection secrets.
Control requests carry the shared API key; health probes and catalog downloads do not. Every request has a total deadline and a response-size limit so a slow or malformed server cannot hold the recovery loop indefinitely.
APIUnavailable
¶
Bases: Exception
Represent transport, authorization, and malformed-response failures uniformly.
NoRedirects
¶
Bases: HTTPRedirectHandler
Keep authentication headers on the configured server.
redirect_request
¶
redirect_request(
req: Request,
fp: IO[bytes],
code: int,
msg: str,
headers: Message,
newurl: str,
) -> None
Reject redirects rather than forwarding a control API key to another destination.
Client
¶
Client(config: Config)
Use Gluetun's existing API and health listener; expose no additional server.
Source code in docker/privateerr/client.py
request
¶
request(
url: str,
*,
timeout: float,
method: str = "GET",
body: Mapping[str, object] | None = None,
key: str = "",
) -> bytes
Send one bounded request and return its body without logging request contents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Complete destination; redirects and inherited proxies are not followed. |
required |
timeout
|
float
|
Maximum total seconds for connection setup and response reads. |
required |
method
|
str
|
HTTP method used for this request. |
'GET'
|
body
|
Mapping[str, object] | None
|
Optional object to encode as JSON for a settings update. |
None
|
key
|
str
|
Optional API credential; omit it for health and catalog requests. |
''
|
Returns:
| Type | Description |
|---|---|
bytes
|
The response body, limited to four MiB. |
Raises:
| Type | Description |
|---|---|
APIUnavailable
|
If transport, status, size, or deadline checks fail. |
Source code in docker/privateerr/client.py
get
¶
Read a control API object, rejecting responses the supervisor cannot interpret.
Source code in docker/privateerr/client.py
apply
¶
Submit connection fields; the supervisor separately verifies settings and health.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Mapping[str, object]
|
Minimal connection update; unrelated Gluetun settings are omitted. |
required |
Raises:
| Type | Description |
|---|---|
APIUnavailable
|
If the response cannot confirm the request. The update may still have succeeded, so callers must reconcile it before retrying. |
Source code in docker/privateerr/client.py
healthy
¶
Probe the separate health listener without sending the control API key.
catalog
¶
Read PIA's advertised regions and WireGuard servers for endpoint selection.
Source code in docker/privateerr/client.py
deadline
¶
Bound DNS, connection setup, and body reads in the single-threaded Linux supervisor.