From a8bff60bb757c255c3c2e36beabe004f5cebd9d9 Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Mon, 30 Jan 2023 12:37:59 +0530 Subject: [PATCH 1/5] add proxy in network --- searx/network/network.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/searx/network/network.py b/searx/network/network.py index e5e2e3855..0452e1e58 100644 --- a/searx/network/network.py +++ b/searx/network/network.py @@ -8,7 +8,7 @@ import asyncio import ipaddress from itertools import cycle from typing import Dict - +from os import environ import httpx from searx import logger, searx_debug @@ -336,6 +336,11 @@ def initialize(settings_engines=None, settings_outgoing=None): settings_engines = settings_engines or settings["engines"] settings_outgoing = settings_outgoing or settings["outgoing"] + if 'SEARX_PROXY_HTTP' in environ: + settings_outgoing.setdefault('proxies', {})['http'] = environ['SEARX_PROXY_HTTP'] + if 'SEARX_PROXY_HTTPS' in environ: + settings_outgoing.setdefault('proxies', {})['https'] = environ['SEARX_PROXY_HTTPS'] + # default parameters for AsyncHTTPTransport # see https://github.com/encode/httpx/blob/e05a5372eb6172287458b37447c30f650047e1b8/httpx/_transports/default.py#L108-L121 # pylint: disable=line-too-long default_params = { -- GitLab From 5ee86dbfec0724844642b4f383c0cdeaaa761277 Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Mon, 30 Jan 2023 12:44:39 +0530 Subject: [PATCH 2/5] fix pylint --- searx/network/network.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/searx/network/network.py b/searx/network/network.py index 0452e1e58..695ec18b9 100644 --- a/searx/network/network.py +++ b/searx/network/network.py @@ -325,7 +325,7 @@ def check_network_configuration(): if exception_count > 0: raise RuntimeError("Invalid network configuration") - +# pylint: disable=too-many-branches def initialize(settings_engines=None, settings_outgoing=None): # pylint: disable=import-outside-toplevel) from searx.engines import engines -- GitLab From 93df6289c7ca05fff563fe761f754ac3d9377086 Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Mon, 30 Jan 2023 12:49:06 +0530 Subject: [PATCH 3/5] fix black --- searx/network/network.py | 1 + 1 file changed, 1 insertion(+) diff --git a/searx/network/network.py b/searx/network/network.py index 695ec18b9..153fe181a 100644 --- a/searx/network/network.py +++ b/searx/network/network.py @@ -325,6 +325,7 @@ def check_network_configuration(): if exception_count > 0: raise RuntimeError("Invalid network configuration") + # pylint: disable=too-many-branches def initialize(settings_engines=None, settings_outgoing=None): # pylint: disable=import-outside-toplevel) -- GitLab From 4564e4b0125b910cf5445a2a3029f7c2dee276b4 Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Mon, 30 Jan 2023 19:31:19 +0530 Subject: [PATCH 4/5] set proxy --- searx/network/network.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/searx/network/network.py b/searx/network/network.py index 153fe181a..3123521ef 100644 --- a/searx/network/network.py +++ b/searx/network/network.py @@ -338,9 +338,9 @@ def initialize(settings_engines=None, settings_outgoing=None): settings_outgoing = settings_outgoing or settings["outgoing"] if 'SEARX_PROXY_HTTP' in environ: - settings_outgoing.setdefault('proxies', {})['http'] = environ['SEARX_PROXY_HTTP'] + settings_outgoing["proxies"]["http"] = environ['SEARX_PROXY_HTTP'] if 'SEARX_PROXY_HTTPS' in environ: - settings_outgoing.setdefault('proxies', {})['https'] = environ['SEARX_PROXY_HTTPS'] + settings_outgoing["proxies"]["https"] = environ['SEARX_PROXY_HTTPS'] # default parameters for AsyncHTTPTransport # see https://github.com/encode/httpx/blob/e05a5372eb6172287458b37447c30f650047e1b8/httpx/_transports/default.py#L108-L121 # pylint: disable=line-too-long -- GitLab From 3953d59d59c4d95125dfe5d75b794be977b83e9a Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Tue, 31 Jan 2023 00:52:35 +0530 Subject: [PATCH 5/5] use dict for proxies --- searx/network/network.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/searx/network/network.py b/searx/network/network.py index 3123521ef..414e33ae2 100644 --- a/searx/network/network.py +++ b/searx/network/network.py @@ -336,7 +336,7 @@ def initialize(settings_engines=None, settings_outgoing=None): settings_engines = settings_engines or settings["engines"] settings_outgoing = settings_outgoing or settings["outgoing"] - + settings_outgoing["proxies"] = {} if 'SEARX_PROXY_HTTP' in environ: settings_outgoing["proxies"]["http"] = environ['SEARX_PROXY_HTTP'] if 'SEARX_PROXY_HTTPS' in environ: -- GitLab