summaryrefslogtreecommitdiff
path: root/searx/webapp.py
diff options
context:
space:
mode:
authorAdam Tauber <asciimoo@gmail.com>2015-01-16 16:26:15 +0100
committerAdam Tauber <asciimoo@gmail.com>2015-01-16 16:26:15 +0100
commit01143f48c527ff7bb98b9a9e3d31f087d7d30ca3 (patch)
treed2ca8412eaf7661a1805ac5de493d34cb72f826e /searx/webapp.py
parent60eb831966a7482ec1bcd7d095241cf2e6fe4dc6 (diff)
downloadsearxng-01143f48c527ff7bb98b9a9e3d31f087d7d30ca3.tar.gz
searxng-01143f48c527ff7bb98b9a9e3d31f087d7d30ca3.zip
[enh] image proxification
Diffstat (limited to 'searx/webapp.py')
-rw-r--r--searx/webapp.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/searx/webapp.py b/searx/webapp.py
index a63c2643f..2e07ddb06 100644
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -29,6 +29,7 @@ import os
from datetime import datetime, timedelta
from requests import get as http_get
from itertools import chain
+from urllib import urlencode
from flask import (
Flask, request, render_template, url_for, Response, make_response,
redirect, send_from_directory
@@ -204,6 +205,18 @@ def url_for_theme(endpoint, override_theme=None, **values):
return url_for(endpoint, **values)
+def image_proxify(url):
+
+ if url.startswith('//'):
+ url = 'https:' + url
+
+ if not settings['server'].get('image_proxy') and not request.cookies.get('image_proxy'):
+ return url
+
+ return '{0}?{1}'.format(url_for('image_proxy'),
+ urlencode(dict(url=url)))
+
+
def render(template_name, override_theme=None, **kwargs):
blocked_engines = request.cookies.get('blocked_engines', '').split(',')
@@ -250,6 +263,8 @@ def render(template_name, override_theme=None, **kwargs):
# override url_for function in templates
kwargs['url_for'] = url_for_theme
+ kwargs['image_proxify'] = image_proxify
+
kwargs['get_result_template'] = get_result_template
kwargs['theme'] = get_current_theme_name(override=override_theme)