From 4a913247b29286299e678e0756119fb62293760f Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Tue, 1 Sep 2020 15:57:35 +0200 Subject: [PATCH] [enh] add option to configure proxies per engine - closes #1827 --- docs/dev/engine_overview.rst | 9 ++++++--- searx/poolrequests.py | 3 ++- searx/search.py | 4 ++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/dev/engine_overview.rst b/docs/dev/engine_overview.rst index c3c81fff..268995a4 100644 --- a/docs/dev/engine_overview.rst +++ b/docs/dev/engine_overview.rst @@ -49,16 +49,19 @@ offline boolean engine runs offline settings.yml ------------ -======================= =========== =========================================== +======================= =========== ============================================= argument type information -======================= =========== =========================================== +======================= =========== ============================================= name string name of search-engine engine string name of searx-engine (filename without ``.py``) shortcut string shortcut of search-engine timeout string specific timeout for search-engine display_error_messages boolean display error messages on the web UI -======================= =========== =========================================== +proxies dict set proxies for a specific engine + (e.g. ``proxies : {http: socks5://proxy:port, + https: socks5://proxy:port}``) +======================= =========== ============================================= overrides diff --git a/searx/poolrequests.py b/searx/poolrequests.py index f9a9d771..9f0ee873 100644 --- a/searx/poolrequests.py +++ b/searx/poolrequests.py @@ -95,7 +95,8 @@ def request(method, url, **kwargs): session = SessionSinglePool() # proxies - kwargs['proxies'] = settings['outgoing'].get('proxies') or None + if kwargs.get('proxies') is None: + kwargs['proxies'] = settings['outgoing'].get('proxies') # timeout if 'timeout' in kwargs: diff --git a/searx/search.py b/searx/search.py index fcc83822..79896e5e 100644 --- a/searx/search.py +++ b/searx/search.py @@ -70,6 +70,10 @@ def send_http_request(engine, request_params): verify=request_params['verify'] ) + # setting engine based proxies + if hasattr(engine, 'proxies'): + request_args['proxies'] = engine.proxies + # specific type of request (GET or POST) if request_params['method'] == 'GET': req = requests_lib.get