llama.cpp icon indicating copy to clipboard operation
llama.cpp copied to clipboard

common: honor HTTP_PROXY/HTTPS_PROXY env vars in http client

Open texasich opened this issue 7 months ago • 14 comments

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_proxy bypass list not implemented yet; can be added as follow-up
  • ALL_PROXY not checked; HTTPS_PROXY and HTTP_PROXY cover the common case
  • std::getenv is available via <cstdlib> already pulled in by httplib.h

texasich avatar Apr 11 '26 01:04 texasich

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.

ggml-gh-bot[bot] avatar Apr 11 '26 01:04 ggml-gh-bot[bot]

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.

texasich avatar Apr 13 '26 18:04 texasich

reopening — #21630 just merged so the new-contributor limit no longer applies. ready for review whenever the maintainers have a minute.

texasich avatar Apr 14 '26 18:04 texasich

Why is this still unmerged?

MoRanYue avatar May 18 '26 09:05 MoRanYue

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. 🙏

texasich avatar May 22 '26 01:05 texasich

Please consider this PR.

BoneGoat avatar May 26 '26 11:05 BoneGoat

+1. Please consider this PR.

nicriverhoo avatar May 27 '26 12:05 nicriverhoo

For a modern software, not respecting to proxy is pretty bad.

MoRanYue avatar May 27 '26 14:05 MoRanYue

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

ngxson avatar May 28 '26 11:05 ngxson

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.

ServeurpersoCom avatar May 28 '26 11:05 ServeurpersoCom

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.

ServeurpersoCom avatar May 28 '26 13:05 ServeurpersoCom

Windows OK, quick test with llama-installer.sh Wine + BorringSSL (default) with Zig. If OK, LGTM.

ServeurpersoCom avatar May 28 '26 13:05 ServeurpersoCom

Dropped the misleading fallback comment — the code only has the two scheme-specific vars, no generic one. Good catch.

texasich avatar May 28 '26 14:05 texasich

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.

ServeurpersoCom avatar May 28 '26 15:05 ServeurpersoCom