on master help sign in
[enh] image proxification
commit01143f48c527ff7bb98b9a9e3d31f087d7d30ca3 authorAdam Tauber <asciimoo@gmail.com> dateFri 16 Jan 2015, 16:26 (12 years ago) parent60eb831
2 files changed+16
searx/settings.yml+1 searx/webapp.py+15
searx/settings.yml+1
@@ -8,6 +8,7 @@ server:
88 default_theme : oscar # ui theme
99 https_rewrite : True # Force rewrite result urls. See searx/https_rewrite.py
1010 useragent_suffix : "" # suffix of searx_useragent, could contain informations like an email address to the administrator
11+ image_proxy : False # Proxying image results through searx
1112
1213engines:
1314 - name : wikipedia
searx/webapp.py+15
@@ -29,6 +29,7 @@ import os
2929from datetime import datetime, timedelta
3030from requests import get as http_get
3131from itertools import chain
32+from urllib import urlencode
3233from flask import (
3334 Flask, request, render_template, url_for, Response, make_response,
3435 redirect, send_from_directory
@@ -204,6 +205,18 @@ def url_for_theme(endpoint, override_theme=None, **values):
204205 return url_for(endpoint, **values)
205206
206207
208+def image_proxify(url):
209+
210+ if url.startswith('//'):
211+ url = 'https:' + url
212+
213+ if not settings['server'].get('image_proxy') and not request.cookies.get('image_proxy'):
214+ return url
215+
216+ return '{0}?{1}'.format(url_for('image_proxy'),
217+ urlencode(dict(url=url)))
218+
219+
207220def render(template_name, override_theme=None, **kwargs):
208221 blocked_engines = request.cookies.get('blocked_engines', '').split(',')
209222
@@ -250,6 +263,8 @@ def render(template_name, override_theme=None, **kwargs):
250263 # override url_for function in templates
251264 kwargs['url_for'] = url_for_theme
252265
266+ kwargs['image_proxify'] = image_proxify
267+
253268 kwargs['get_result_template'] = get_result_template
254269
255270 kwargs['theme'] = get_current_theme_name(override=override_theme)