common: honor HTTP_PROXY/HTTPS_PROXY env vars in http client
Fixes #21694
What
common_http_client() builds the httplib client but never checks standard proxy environment variables, so any download that goes through this path (e.g. -hf flag, model presets) silently fails in environments that require a proxy.
How
After constructing the client, read HTTPS_PROXY/https_proxy for https:// URLs and HTTP_PROXY/http_proxy for http:// ones (scheme-specific takes precedence). If set and parseable, pass it to cli.set_proxy() and optionally cli.set_proxy_basic_auth(). Malformed proxy URLs are caught and silently ignored so nothing breaks for callers without a proxy configured.
Reuses the existing common_http_parse_url() to handle auth credentials embedded in the proxy URL (e.g. http://user:pass@proxy:3128).
Notes
NO_PROXY/no_proxybypass list not implemented yet; can be added as follow-upALL_PROXYnot checked; HTTPS_PROXY and HTTP_PROXY cover the common casestd::getenvis available via<cstdlib>already pulled in by httplib.h
Hi @texasich, thanks for your contribution!
Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
- Multiple open PRs from a new contributor: We limit new contributors (those without a previously merged PR) to 1 open PR at a time. You currently have 2 open PRs.
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.
closing this to get back under the 1-PR limit for new contributors — #21630 is closer to merging so keeping that one active. will reopen this once that lands. branch is preserved on my fork.
reopening — #21630 just merged so the new-contributor limit no longer applies. ready for review whenever the maintainers have a minute.
Why is this still unmerged?
Gentle nudge on this one — been open a while. Happy to rebase if there are conflicts, or make any changes needed. Let me know if anything's blocking review. 🙏
Please consider this PR.
+1. Please consider this PR.
For a modern software, not respecting to proxy is pretty bad.
I'd assume most maintainers don't use proxy so no one can confidently review / test this PR (me including)
Asking @ServeurpersoCom for your thoughts about this feature / this implementation
Need to methodically test the HTTP client on Linux and on Windows with a small Squid as a classic enterprise forward proxy... I'm setting up the platform and will keep you updated.
Tested this and the proxy path works fine for -hf, both direct and through the proxy, Linux only. Windows check in progress.
A few non-blocking notes:
-
NO_PROXY/no_proxy isn't honored. The client also fetches arbitrary --model-url, docker manifests and runtime image_url, but those are all external targets so it's not urgent, possible follow-up.
-
A malformed proxy url is caught silently, so it fails open and falls back to a direct connection with no log. A LOG_WRN in the catch would make that debuggable.
-
nit: for http you read uppercase HTTP_PROXY first. Out of habit a lot of code only trusts lowercase http_proxy for the http scheme and ignores the uppercase form, since httpoxy (see: https://httpoxy.org). It doesn't apply here since this isn't CGI, so it's purely cosmetic.
-
nit: the comment mentions checking the scheme var then a generic fallback, but both vars are scheme specific and there's no generic one, so it doesn't match the code.
Windows OK, quick test with llama-installer.sh Wine + BorringSSL (default) with Zig. If OK, LGTM.
Dropped the misleading fallback comment — the code only has the two scheme-specific vars, no generic one. Good catch.
It's a minimalist proxy support that will unlock GGUF downloads for a lot of users, and we can easily do a follow-up PR later if we need to expand it. You could add the env var to the docs, but it's a super standard one for every web app on Linux.