From a4b9ffa681f463655dd62aed1d30a7a3b5e281ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Rosenkr=C3=A4nzer?= Date: Fri, 13 Mar 2026 16:51:05 +0100 Subject: [PATCH] Load and register requests_unixsocket if it is available This allows talking to rspamd (and probably other backends) over a UNIX socket instead of requiring a TCP socket, e.g. options: antispamUrl: "http+unix://%2Frun%2Frspamd%2Fcontroller.sock" The change in endpoints/system/misc.py is needed because requests_unixsocket (at least the current version, 0.4.1) implements only the version of "get" with one positional argument. --- endpoints/system/misc.py | 2 +- main.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/endpoints/system/misc.py b/endpoints/system/misc.py index 05702df..c6286a3 100644 --- a/endpoints/system/misc.py +++ b/endpoints/system/misc.py @@ -199,7 +199,7 @@ def rspamdProxy(path): if path not in conf["antispamEndpoints"]: return jsonify(message="Endpoint not allowed"), 403 try: - res = requests.get(conf["antispamUrl"]+"/"+path, request.args, stream=True) + res = requests.get(conf["antispamUrl"]+"/"+path, params=request.args, stream=True) except BaseException as err: API.logger.error(type(err).__name__+": "+" - ".join(str(arg) for arg in err.args)) return jsonify(message="Failed to connect to antispam"), 503 diff --git a/main.py b/main.py index e5c1172..6e91a01 100755 --- a/main.py +++ b/main.py @@ -9,6 +9,14 @@ in combination with a WSGI server using the API object as callable """ +# If it is available, load requests_unixsocket and register it globally. +# This allows e.g. antispamUrl: http+unix://%2Frun%2Frspamd%2Fcontroller.sock +try: + import requests_unixsocket + requests_unixsocket.monkeypatch() +except Exception: + pass + if __name__ == '__main__': import os import sys