Bläddra i källkod

Merge pull request #297 from dalf/proxies

[enh] Implement http proxies for outgoing requests. (see #236)
Adam Tauber 10 år sedan
förälder
incheckning
1f0e6ce65b
3 ändrade filer med 14 tillägg och 2 borttagningar
  1. 3
    1
      searx/poolrequests.py
  2. 7
    0
      searx/settings.yml
  3. 4
    1
      searx/webapp.py

+ 3
- 1
searx/poolrequests.py Visa fil

66
 
66
 
67
 
67
 
68
 def request(method, url, **kwargs):
68
 def 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

+ 7
- 0
searx/settings.yml Visa fil

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:

+ 4
- 1
searx/webapp.py Visa fil

111
                    gettext('news'),
111
                    gettext('news'),
112
                    gettext('map'))
112
                    gettext('map'))
113
 
113
 
114
+outgoing_proxies = settings.get('outgoing_proxies', None)
115
+
114
 
116
 
115
 @babel.localeselector
117
 @babel.localeselector
116
 def get_locale():
118
 def get_locale():
645
     resp = requests.get(url,
647
     resp = requests.get(url,
646
                         stream=True,
648
                         stream=True,
647
                         timeout=settings['server'].get('request_timeout', 2),
649
                         timeout=settings['server'].get('request_timeout', 2),
648
-                        headers=headers)
650
+                        headers=headers,
651
+                        proxies=outgoing_proxies)
649
 
652
 
650
     if resp.status_code == 304:
653
     if resp.status_code == 304:
651
         return '', resp.status_code
654
         return '', resp.status_code