summaryrefslogtreecommitdiff
path: root/searx/templates
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2021-04-03 13:56:47 +0200
committerMarkus Heiser <markus@darmarit.de>2021-04-05 14:34:45 +0200
commit87e4c476216ab25206b4e583b4206e762c3b9fe0 (patch)
treeba0e363cd327fdd3122813dab313c597b5150266 /searx/templates
parent9292571304376c2c463fb26ee0db89298bb00e6c (diff)
downloadsearxng-87e4c476216ab25206b4e583b4206e762c3b9fe0.tar.gz
searxng-87e4c476216ab25206b4e583b4206e762c3b9fe0.zip
[fix] url_for(..., _external=True) in templates
The `url_for` function in the template context is not the one from Flask, it is the one from `webapp`. The `webapp.url_for_theme` is different from its namesake of Flask and has it quirks, when called with argument `_external=True`. The `webapp.url_for_theme` can't handle absolute URLs since it pokes a leading '/', here is the snippet of the old code:: url = url_for(endpoint, **values) if settings['server']['base_url']: if url.startswith('/'): url = url[1:] url = urljoin(settings['server']['base_url'], url) Next drawback of (Flask's) `_external=True` is, that it will not return the HTTP scheme when searx (the Flask app) listens on http and is proxied by a https server. To get the right scheme `HTTP_X_SCHEME` is needed by Flask (werkzeug). Since this is not provided in every environment (e.g. behind Apache mod_wsgi or the HTTP header is not fully set for some other reasons) it is recommended to get *script_name*, *server* and *scheme* from the configured `base_url`. If `base_url` is specified, then these values from are given preference over any Flask's generics. BTW this patch normalize to use `url_for` in the `opensearch.xml` and drop the need of `host` and `urljoin` in template's context. Signed-off-by: Markus Heiser <markus@darmarit.de>
Diffstat (limited to 'searx/templates')
-rw-r--r--searx/templates/__common__/opensearch.xml4
1 files changed, 2 insertions, 2 deletions
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 @@
<ShortName>{{ instance_name }}</ShortName>
<Description>a privacy-respecting, hackable metasearch engine</Description>
<InputEncoding>UTF-8</InputEncoding>
- <Image>{{ urljoin(host, url_for('static', filename='img/favicon.png')) }}</Image>
+ <Image>{{ url_for('static', filename='img/favicon.png', _external=True) }}</Image>
<LongName>searx metasearch</LongName>
{% if opensearch_method == 'get' %}
<Url rel="results" type="text/html" method="get" template="{{ url_for('search', _external=True) }}?q={searchTerms}"/>
@@ -13,7 +13,7 @@
</Url>
{% endif %}
{% if autocomplete %}
- <Url rel="suggestions" type="application/x-suggestions+json" template="{{ host }}autocompleter?q={searchTerms}"/>
+ <Url rel="suggestions" type="application/x-suggestions+json" template="{{ url_for('autocompleter', _external=True) }}?q={searchTerms}"/>
{% endif %}
<Url type="application/opensearchdescription+xml"