on master help sign in
[enh] basic support for http proxy (see #236)
cde37beAlexandre Flament
searx/poolrequests.py+3−1
@@ -66,8 +66,10 @@ class SessionSinglePool(requests.Session):
66
66
67
67
68def request(method, url, **kwargs):
68def 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
70 session = SessionSinglePool()
71 session = SessionSinglePool()
72+ kwargs['proxies'] = settings.get('outgoing_proxies', None)
71 response = session.request(method=method, url=url, **kwargs)
73 response = session.request(method=method, url=url, **kwargs)
72 session.close()
74 session.close()
73 return response
75 return response
searx/settings.yml+7
@@ -10,6 +10,13 @@ server:
10 image_proxy : False # Proxying image results through searx
10 image_proxy : False # Proxying image results through searx
11 default_locale : "" # Default interface locale - leave blank to detect from browser information or use codes from the 'locales' config section
11 default_locale : "" # Default interface locale - leave blank to detect from browser information or use codes from the 'locales' config section
12
12
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+
13# uncomment below section only if you have more than one network interface
20# uncomment below section only if you have more than one network interface
14# which can be the source of outgoing search requests
21# which can be the source of outgoing search requests
15#source_ips:
22#source_ips:
searx/webapp.py+3−1
@@ -110,6 +110,7 @@ _category_names = (gettext('files'),
110 gettext('news'),
110 gettext('news'),
111 gettext('map'))
111 gettext('map'))
112
112
113+outgoing_proxies = settings.get('outgoing_proxies', None)
113
114
114@babel.localeselector
115@babel.localeselector
115def get_locale():
116def get_locale():
@@ -638,7 +639,8 @@ def image_proxy():
638 resp = requests.get(url,
639 resp = requests.get(url,
639 stream=True,
640 stream=True,
640 timeout=settings['server'].get('request_timeout', 2),
641 timeout=settings['server'].get('request_timeout', 2),
641− headers=headers)
642+ headers=headers,
643+ proxies=outgoing_proxies)
642
644
643 if resp.status_code == 304:
645 if resp.status_code == 304:
644 return '', resp.status_code
646 return '', resp.status_code