diff --git a/searx/templates/__common__/opensearch.xml b/searx/templates/__common__/opensearch.xml
index 2476258c0..230f327a5 100644
--- a/searx/templates/__common__/opensearch.xml
+++ b/searx/templates/__common__/opensearch.xml
@@ -3,7 +3,7 @@
{{ instance_name }}
a privacy-respecting, hackable metasearch engine
UTF-8
- {{ urljoin(host, url_for('static', filename='img/favicon.png')) }}
+ {{ url_for('static', filename='img/favicon.png', _external=True) }}
searx metasearch
{% if opensearch_method == 'get' %}
@@ -13,7 +13,7 @@
{% endif %}
{% if autocomplete %}
-
+
{% endif %}
= 0:
method = 'get'
- ret = render('opensearch.xml',
- opensearch_method=method,
- host=get_base_url(),
- urljoin=urljoin,
- override_theme='__common__')
+ ret = render(
+ 'opensearch.xml',
+ opensearch_method=method,
+ override_theme='__common__'
+ )
resp = Response(response=ret,
status=200,
@@ -1027,7 +1016,7 @@ def favicon():
@app.route('/clear_cookies')
def clear_cookies():
- resp = make_response(redirect(urljoin(settings['server']['base_url'], url_for('index'))))
+ resp = make_response(redirect(url_for('index', _external=True)))
for cookie_name in request.cookies:
resp.delete_cookie(cookie_name)
return resp
@@ -1128,19 +1117,38 @@ class ReverseProxyPathFix:
'''
def __init__(self, app):
+
self.app = app
+ self.script_name = None
+ self.scheme = None
+ self.server = None
+
+ if settings['server']['base_url']:
+
+ # If base_url is specified, then these values from are given
+ # preference over any Flask's generics.
+
+ base_url = urlparse(settings['server']['base_url'])
+ self.script_name = base_url.path
+ self.scheme = base_url.scheme
+ self.server = base_url.netloc
def __call__(self, environ, start_response):
- script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
+
+ script_name = self.script_name or environ.get('HTTP_X_SCRIPT_NAME', '')
if script_name:
environ['SCRIPT_NAME'] = script_name
path_info = environ['PATH_INFO']
if path_info.startswith(script_name):
environ['PATH_INFO'] = path_info[len(script_name):]
- scheme = environ.get('HTTP_X_SCHEME', '')
+ scheme = self.scheme or environ.get('HTTP_X_SCHEME', '')
if scheme:
environ['wsgi.url_scheme'] = scheme
+
+ server = self.server or environ.get('HTTP_X_FORWARDED_HOST', '')
+ if server:
+ environ['HTTP_HOST'] = server
return self.app(environ, start_response)