From cde37be4f594451c1b791b7a3a66d78c2bc44d54 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Sat, 25 Apr 2015 11:44:53 +0200 Subject: [PATCH 1/2] [enh] basic support for http proxy (see #236) --- searx/poolrequests.py | 4 +++- searx/settings.yml | 7 +++++++ searx/webapp.py | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/searx/poolrequests.py b/searx/poolrequests.py index b74d43a02..e2a757665 100644 --- a/searx/poolrequests.py +++ b/searx/poolrequests.py @@ -66,8 +66,10 @@ class SessionSinglePool(requests.Session): def request(method, url, **kwargs): - """same as requests/requests/api.py request(...) except it use SessionSinglePool""" + """same as requests/requests/api.py request(...) except it use SessionSinglePool and force proxies""" + global settings session = SessionSinglePool() + kwargs['proxies'] = settings.get('outgoing_proxies', None) response = session.request(method=method, url=url, **kwargs) session.close() return response diff --git a/searx/settings.yml b/searx/settings.yml index f37c56b26..cf7680090 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -10,6 +10,13 @@ server: image_proxy : False # Proxying image results through searx default_locale : "" # Default interface locale - leave blank to detect from browser information or use codes from the 'locales' config section +# uncomment below section if you want to use a proxy +# see http://docs.python-requests.org/en/latest/user/advanced/#proxies +# SOCKS proxies are not supported : see https://github.com/kennethreitz/requests/pull/478 +#outgoing_proxies : +# http : http://127.0.0.1:8080 +# https: http://127.0.0.1:8080 + # uncomment below section only if you have more than one network interface # which can be the source of outgoing search requests #source_ips: diff --git a/searx/webapp.py b/searx/webapp.py index 52ced1363..8a0adefd5 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -110,6 +110,7 @@ _category_names = (gettext('files'), gettext('news'), gettext('map')) +outgoing_proxies = settings.get('outgoing_proxies', None) @babel.localeselector def get_locale(): @@ -638,7 +639,8 @@ def image_proxy(): resp = requests.get(url, stream=True, timeout=settings['server'].get('request_timeout', 2), - headers=headers) + headers=headers, + proxies=outgoing_proxies) if resp.status_code == 304: return '', resp.status_code From 83e48fa89bd28a38b46a717d786cc7bfad26ff21 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Sat, 25 Apr 2015 12:05:35 +0200 Subject: [PATCH 2/2] flake8 fix --- searx/webapp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/searx/webapp.py b/searx/webapp.py index 8a0adefd5..3b6ac6591 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -112,6 +112,7 @@ _category_names = (gettext('files'), outgoing_proxies = settings.get('outgoing_proxies', None) + @babel.localeselector def get_locale(): locale = request.accept_languages.best_match(settings['locales'].keys())