on master help sign in
Merge pull request #297 from dalf/proxies

[enh] Implement http proxies for outgoing requests. (see #236)

commit1f0e6ce65ba5e255f423ad8ec6967d67fd4aec0b authorAdam Tauber <asciimoo@gmail.com> dateSun 26 Apr 2015, 12:19 (12 years ago) parent952473d83e48fa
3 files changed+14−2
searx/poolrequests.py+3−1 searx/settings.yml+7 searx/webapp.py+4−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+4−1
@@ -111,6 +111,8 @@ _category_names = (gettext('files'),
111111 gettext('news'),
112112 gettext('map'))
113113
114+outgoing_proxies = settings.get('outgoing_proxies', None)
115+
114116
115117@babel.localeselector
116118def get_locale():
@@ -645,7 +647,8 @@ def image_proxy():
645647 resp = requests.get(url,
646648 stream=True,
647649 timeout=settings['server'].get('request_timeout', 2),
648− headers=headers)
650+ headers=headers,
651+ proxies=outgoing_proxies)
649652
650653 if resp.status_code == 304:
651654 return '', resp.status_code