From 0dec814fe75fa7c5452f3d6defaef76a0cfc2451 Mon Sep 17 00:00:00 2001 From: Luiz Angelo Daros de Luca Date: Tue, 10 Mar 2026 17:33:09 -0300 Subject: [PATCH] owut: add proxy support via env vars Support HTTP and HTTPS proxies by reading http_proxy and https_proxy environment variables. Although owut uses HTTPS URLs by default (making https_proxy the only used variable), the implementation supports both. The implementation uses uclient's set_proxy_url() to handle tunneling, allowing fetching firmware and lists through an HTTP proxy. The following scenarios are covered: - HTTP/HTTPS requests via an HTTP proxy. - HTTP/HTTPS requests via an HTTPS proxy (requires a valid certificate for the proxy server). Current limitations: - Proxy authentication is not supported yet. - The no_proxy environment variable is not supported. - Cannot yet skip HTTPS proxy certificate validation nor define a custom one for the proxy connection itself. Fixes #54 Signed-off-by: Luiz Angelo Daros de Luca --- files/owut | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/files/owut b/files/owut index 6e98ee4..c42be66 100755 --- a/files/owut +++ b/files/owut @@ -371,6 +371,12 @@ function _get_ca_files() let _uc_uc = null; let _uc_cb = null; +function _url_scheme(url) +{ + let m = match(url, /^([A-Za-z][A-Za-z0-9+.-]*):\/\//); + return m ? m[1] : null; +} + function _get_uclient(url, dst_file) { if (! _uc_uc) { @@ -434,7 +440,30 @@ function _get_uclient(url, dst_file) } - _uc_uc.set_url(url); + let scheme = _url_scheme(url); + if (! scheme || ! match(scheme, /^https?$/i)) { + L.die("Invalid request URL (expected http or https):\n %s\n", url); + } + + let proxy = null; + if (match(scheme, /^https$/i)) { + proxy = getenv("https_proxy"); + } else { + proxy = getenv("http_proxy"); + } + + if (proxy) { + let proxy_scheme = _url_scheme(proxy); + if (! proxy_scheme || ! match(proxy_scheme, /^https?$/i)) { + L.die("Invalid proxy URL (expected http or https):\n %s\n", proxy); + } + + _uc_uc.set_url(proxy_url); + _uc_uc.set_proxy_url(url); + } else { + _uc_uc.set_url(url); + } + _uc_cb.url = url; _uc_cb.dst_file = dst_file;