From 35e0d827faebb5071eeae5f320fcedea6b21ff0f Mon Sep 17 00:00:00 2001 From: imSp4rky Date: Wed, 25 Nov 2026 16:53:02 -0700 Subject: [PATCH] fix(api): leave Gluetun out of a server download job's proxy providers --- docs/guide/proxies-and-vpn.md | 14 ++++++-------- docs/reference/configuration/network.md | 5 +++-- tests/remote/unit/test_handler_proxy_policy.py | 5 +++-- unshackle/core/api/download_manager.py | 4 +++- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/docs/guide/proxies-and-vpn.md b/docs/guide/proxies-and-vpn.md index 7a10dd92..a158f29f 100644 --- a/docs/guide/proxies-and-vpn.md +++ b/docs/guide/proxies-and-vpn.md @@ -580,6 +580,11 @@ in unshackle itself. Give `--remote` a proxy the server can reach, or run the service locally. A server on this machine (a `remote_services` URL on `127.0.0.1`) can reach a local proxy, so it is exempt. +!!! warning "Not available on a server" + `unshackle serve` does not load Gluetun. A REST API request, a download job and a + remote session cannot use a `gluetun:` proxy, also for an API key with `server_proxy`. + Use Gluetun with `dl` or `search` on your own machine. + !!! warning "Docker is required" Gluetun needs a working [Docker](https://docs.docker.com/get-docker/) installation on your `PATH`. If Docker is not found, the proxy provider fails to load. The container also needs the `NET_ADMIN` capability and access @@ -1043,19 +1048,12 @@ proxy_providers: The returned proxy is HTTPS on **port 443**. -!!! warning "Windscribe is not loaded by the REST API resolver" - The `dl` command loads the standalone Windscribe proxy provider (and Gluetun), but - the proxy resolver that the REST API and the remote-download client use does **not**. - If you drive downloads through the API and need Windscribe or Gluetun exits, get the - proxy on the CLI side, or use a different proxy provider for API jobs. See the - developer note below. - ## Developer notes !!! note "One resolution path (developers)" `dl`, `search`, the REST API handlers and the remote-service client all load proxy providers through `load_proxy_providers()` in `unshackle/core/proxies/resolve.py`. - The REST API and the remote-service client call it through + The REST API, its download jobs and the remote-service client call it through `initialize_proxy_providers()`, which leaves out Gluetun because Gluetun starts a local Docker container. All paths accept the same query grammar: a direct URI, a `provider:query`, a bare query tried against providers in order, or a `controld://` diff --git a/docs/reference/configuration/network.md b/docs/reference/configuration/network.md index ec8d14f2..34d13721 100644 --- a/docs/reference/configuration/network.md +++ b/docs/reference/configuration/network.md @@ -105,6 +105,7 @@ Config keys of the Control D proxy provider. See | `max_profiles` | `int` | `4` | The most profiles unshackle uses: your pairs plus the `unshackle-*` endpoints on the account. It must be 1 or more. unshackle creates an `unshackle-` profile and endpoint only while the total is lower. | !!! note "Provider loading differs between CLI and REST server" - The `dl` CLI loads all providers, including `gluetun`. The REST API / remote-client path - does **not** load `gluetun`, because it starts a local Docker container. ExpressVPN and ProtonVPN also auto-load when their cached session exists, and Hola + The `dl` and `search` commands load all providers, including `gluetun`. A server (REST API + requests, download jobs and remote sessions) and the remote client do **not** load `gluetun`, + because it starts a local Docker container. ExpressVPN and ProtonVPN also auto-load when their cached session exists, and Hola auto-loads whenever the `hola-proxy` binary is present. diff --git a/tests/remote/unit/test_handler_proxy_policy.py b/tests/remote/unit/test_handler_proxy_policy.py index 022b64dd..e2293cb8 100644 --- a/tests/remote/unit/test_handler_proxy_policy.py +++ b/tests/remote/unit/test_handler_proxy_policy.py @@ -303,9 +303,9 @@ class TestDownloadEnforcement: created = created_params({"service": "EXAMPLE", "title_id": "t1"}, request("proxykey")) assert created["server_proxy"] is True - @pytest.mark.parametrize(("params", "expected"), [({}, []), ({"server_proxy": True}, None)]) + @pytest.mark.parametrize(("params", "expected"), [({}, []), ({"server_proxy": True}, ["server"])]) def test_perform_download_maps_stamp_to_dl_providers(self, monkeypatch, tmp_path, params, expected): - """An unstamped or denied job hands dl an empty provider list; a stamped one loads config.""" + """An unstamped or denied job hands dl an empty provider list; a stamped one gets the server's list.""" from unshackle.commands import dl as dl_module from unshackle.core.api import download_manager as dm @@ -325,6 +325,7 @@ class TestDownloadEnforcement: monkeypatch.setattr(dl_module, "dl", FakeDl) monkeypatch.setattr("unshackle.core.services.Services.get_path", staticmethod(lambda service: tmp_path)) monkeypatch.setattr(handlers, "load_full_cdm", lambda *args: None) + monkeypatch.setattr("unshackle.core.proxies.resolve.initialize_proxy_providers", lambda **_: ["server"]) with pytest.raises(Stop): dm.perform_download("job1", "EXAMPLE", "t1", dict(params)) diff --git a/unshackle/core/api/download_manager.py b/unshackle/core/api/download_manager.py index a2e89acf..d234be5a 100644 --- a/unshackle/core/api/download_manager.py +++ b/unshackle/core/api/download_manager.py @@ -412,11 +412,13 @@ def perform_download( from unshackle.core.api.handlers import DL_TRANSPORT_KEYS, instantiate_service, relay_label from unshackle.core.launch import launch + from unshackle.core.proxies.resolve import initialize_proxy_providers from unshackle.core.run_plan import RunStopped, api_plan ctx = api_plan(params, client_sent_keys(params)).context(dl.cli, service) launch(ctx, {"client_argv": f"{relay_label(params)} download job {job_id}"}) - dl_instance = dl(ctx=ctx, proxy_providers=None if params.get("server_proxy") is True else [], **ctx.params) + providers = initialize_proxy_providers(quiet=True) if params.get("server_proxy") is True else [] + dl_instance = dl(ctx=ctx, proxy_providers=providers, **ctx.params) # Per-request credential ("user:pass"); feed it into the map get_credentials() reads so a # client can authenticate without anything being persisted to disk. Without a profile, # get_credentials() falls back to "default", so store it there too rather than dropping it