From 6febaeeb1b5f64a9a3092b0ba1a3591441f7294d Mon Sep 17 00:00:00 2001 From: miruka Date: Tue, 2 Mar 2021 12:32:48 -0400 Subject: [PATCH] Support the http_proxy environment variable Overrides General.proxy setting if set --- docs/CHANGELOG.md | 3 +++ src/backend/matrix_client.py | 4 +++- src/gui/ArgumentParser.qml | 1 + src/utils.h | 4 +++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index ba41b1d3..8c4b74af 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -61,6 +61,9 @@ and this project adheres to - Add command-line arguments parsing and a `--start-in-tray` option, see `mirage --help` +- Support for HTTP and SOCKS5 proxies, can be set in config file or using the + `http_proxy` environment variable + - Hovering on stability percentages in the sign-in page's homeserver list now shows more detailed tooltips about the server's recent downtimes diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index ccecacab..2dd764b2 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -7,6 +7,7 @@ import asyncio import html import io import logging as log +import os import platform import re import textwrap @@ -167,7 +168,8 @@ class MatrixClient(nio.AsyncClient): store = Path(backend.appdirs.user_data_dir) / "encryption" store.mkdir(parents=True, exist_ok=True) - proxy = backend.settings.General.proxy + proxy: Optional[str] + proxy = os.environ.get("http_proxy", backend.settings.General.proxy) host = re.sub(r":\d+$", "", urlparse(homeserver).netloc) if host in ("127.0.0.1", "localhost", "::1"): diff --git a/src/gui/ArgumentParser.qml b/src/gui/ArgumentParser.qml index e596991f..8a2e2ae8 100644 --- a/src/gui/ArgumentParser.qml +++ b/src/gui/ArgumentParser.qml @@ -21,6 +21,7 @@ QtObject { MIRAGE_CONFIG_DIR Override the default configuration folder MIRAGE_DATA_DIR Override the default application data folder MIRAGE_CACHE_DIR Override the default cache and downloads folder + http_proxy Override the General.proxy setting, see settings.py ` readonly property bool ready: { diff --git a/src/utils.h b/src/utils.h index b6fd3caf..e71b598f 100644 --- a/src/utils.h +++ b/src/utils.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #ifdef Q_OS_LINUX @@ -92,6 +92,8 @@ public slots: } void setProxy(QUrl url) const { + const QUrl envProxy = QUrl(qEnvironmentVariable("http_proxy")); + if (! envProxy.isEmpty()) url = envProxy; if (url.isEmpty()) return; const QString scheme = url.scheme();