Browse Source

[enh] add option to configure proxies per engine - closes #1827

Adam Tauber 4 years ago
parent
commit
4a913247b2
3 changed files with 12 additions and 4 deletions
  1. 6 3
      docs/dev/engine_overview.rst
  2. 2 1
      searx/poolrequests.py
  3. 4 0
      searx/search.py

+ 6 - 3
docs/dev/engine_overview.rst

@@ -49,16 +49,19 @@ offline                 boolean     engine runs offline
 settings.yml
 settings.yml
 ------------
 ------------
 
 
-======================= =========== ===========================================
+======================= =========== =============================================
 argument                type        information
 argument                type        information
-======================= =========== ===========================================
+======================= =========== =============================================
 name                    string      name of search-engine
 name                    string      name of search-engine
 engine                  string      name of searx-engine
 engine                  string      name of searx-engine
                                     (filename without ``.py``)
                                     (filename without ``.py``)
 shortcut                string      shortcut of search-engine
 shortcut                string      shortcut of search-engine
 timeout                 string      specific timeout for search-engine
 timeout                 string      specific timeout for search-engine
 display_error_messages  boolean     display error messages on the web UI
 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
 overrides

+ 2 - 1
searx/poolrequests.py

@@ -95,7 +95,8 @@ def request(method, url, **kwargs):
     session = SessionSinglePool()
     session = SessionSinglePool()
 
 
     # proxies
     # proxies
-    kwargs['proxies'] = settings['outgoing'].get('proxies') or None
+    if kwargs.get('proxies') is None:
+        kwargs['proxies'] = settings['outgoing'].get('proxies')
 
 
     # timeout
     # timeout
     if 'timeout' in kwargs:
     if 'timeout' in kwargs:

+ 4 - 0
searx/search.py

@@ -70,6 +70,10 @@ def send_http_request(engine, request_params):
         verify=request_params['verify']
         verify=request_params['verify']
     )
     )
 
 
+    # setting engine based proxies
+    if hasattr(engine, 'proxies'):
+        request_args['proxies'] = engine.proxies
+
     # specific type of request (GET or POST)
     # specific type of request (GET or POST)
     if request_params['method'] == 'GET':
     if request_params['method'] == 'GET':
         req = requests_lib.get
         req = requests_lib.get