on master help sign in
[enh] basic support for http proxy (see #236)
commitcde37be4f594451c1b791b7a3a66d78c2bc44d54 authorAlexandre Flament <alex@al-f.net> dateSat 25 Apr 2015, 11:44 (12 years ago) parent3351625
3 files changed+13−2
searx/poolrequests.py+3−1 searx/settings.yml+7 searx/webapp.py+3−1
searx/poolrequests.py+3−1
@@ -66,8 +66,10 @@ class SessionSinglePool(requests.Session):
6666
6767
6868def request(method, url, **kwargs):
69− """same as requests/requests/api.py request(...) except it use SessionSinglePool"""
69+ """same as requests/requests/api.py request(...) except it use SessionSinglePool and force proxies"""
70+ global settings
7071 session = SessionSinglePool()
72+ kwargs['proxies'] = settings.get('outgoing_proxies', None)
7173 response = session.request(method=method, url=url, **kwargs)
7274 session.close()
7375 return response
searx/settings.yml+7
@@ -10,6 +10,13 @@ server:
1010 image_proxy : False # Proxying image results through searx
1111 default_locale : "" # Default interface locale - leave blank to detect from browser information or use codes from the 'locales' config section
1212
13+# uncomment below section if you want to use a proxy
14+# see http://docs.python-requests.org/en/latest/user/advanced/#proxies
15+# SOCKS proxies are not supported : see https://github.com/kennethreitz/requests/pull/478
16+#outgoing_proxies :
17+# http : http://127.0.0.1:8080
18+# https: http://127.0.0.1:8080
19+
1320# uncomment below section only if you have more than one network interface
1421# which can be the source of outgoing search requests
1522#source_ips:
searx/webapp.py+3−1
@@ -110,6 +110,7 @@ _category_names = (gettext('files'),
110110 gettext('news'),
111111 gettext('map'))
112112
113+outgoing_proxies = settings.get('outgoing_proxies', None)
113114
114115@babel.localeselector
115116def get_locale():
@@ -638,7 +639,8 @@ def image_proxy():
638639 resp = requests.get(url,
639640 stream=True,
640641 timeout=settings['server'].get('request_timeout', 2),
641− headers=headers)
642+ headers=headers,
643+ proxies=outgoing_proxies)
642644
643645 if resp.status_code == 304:
644646 return '', resp.status_code