[fix] opensearch.xml URL contains method and autocomplete parameters
When the user add searx as a search engine, the browser loads the /opensearch.xml URL without the cookies.
Without the query parameters, the user preferences are ignored (method and autocomplete).
In addition, opensearch.xml is modified to support automatic updates,
see https://developer.mozilla.org/en-US/docs/Web/OpenSearch
commitbfdad7bc0f867f67675c1d8c539c58e82f450c58
authorAlexandre Flament <alex@al-f.net>
dateMon 5 Oct 2020, 15:38 (6 years ago)
parent584760c
searx/templates/__common__/opensearch.xml+4
@@ -15,4 +15,8 @@
1515 {% if autocomplete %}
1616 <Url rel="suggestions" type="application/x-suggestions+json" template="{{ host }}autocompleter?q={searchTerms}"/>
1717 {% endif %}
18+
19+ <Url type="application/opensearchdescription+xml"
20+ rel="self"
21+ template="{{ opensearch_url }}" />
1822</OpenSearchDescription>
searx/templates/__common__/opensearch_response_rss.xml+1−1
@@ -9,7 +9,7 @@
99 <opensearch:totalResults>{{ number_of_results }}</opensearch:totalResults>
1010 <opensearch:startIndex>1</opensearch:startIndex>
1111 <opensearch:itemsPerPage>{{ number_of_results }}</opensearch:itemsPerPage>
12− <atom:link rel="search" type="application/opensearchdescription+xml" href="{{ base_url }}opensearch.xml"/>
12+ <atom:link rel="search" type="application/opensearchdescription+xml" href="{{ opensearch_url }}"/>
1313 <opensearch:Query role="request" searchTerms="{{ q|e }}" startPage="1" />
1414 {% if error_message %}
1515 <item>
searx/templates/courgette/base.html+1−1
@@ -22,7 +22,7 @@
2222 {% endblock %}
2323 {% block meta %}{% endblock %}
2424 {% block head %}
25− <link title="{{ instance_name }}" type="application/opensearchdescription+xml" rel="search" href="{{ url_for('opensearch') }}"/>
25+ <link title="{{ instance_name }}" type="application/opensearchdescription+xml" rel="search" href="{{ opensearch_url }}"/>
2626 {% endblock %}
2727 <script type="text/javascript">
2828 searx = {};
searx/templates/legacy/base.html+1−1
@@ -17,7 +17,7 @@
1717 {% endblock %}
1818 {% block meta %}{% endblock %}
1919 {% block head %}
20− <link title="{{ instance_name }}" type="application/opensearchdescription+xml" rel="search" href="{{ url_for('opensearch') }}"/>
20+ <link title="{{ instance_name }}" type="application/opensearchdescription+xml" rel="search" href="{{ opensearch_url }}"/>
2121 {% endblock %}
2222 </head>
2323 <body class="{{ endpoint }}_endpoint" >
searx/templates/oscar/base.html+1−1
@@ -37,7 +37,7 @@
3737 {% block head %}
3838 {% endblock %}
3939
40− <link title="{{ instance_name }}" type="application/opensearchdescription+xml" rel="search" href="{{ url_for('opensearch') }}"/>
40+ <link title="{{ instance_name }}" type="application/opensearchdescription+xml" rel="search" href="{{ opensearch_url }}"/>
4141 <noscript>
4242 <style type="text/css">
4343 .tab-content > .active_if_nojs, .active_if_nojs {display: block !important; visibility: visible !important;}
searx/templates/simple/base.html+1−1
@@ -29,7 +29,7 @@
2929 data-no-item-found="{{ _('No item found') }}"></script>
3030 <!--<![endif]-->
3131 {% block head %}
32− <link title="{{ instance_name }}" type="application/opensearchdescription+xml" rel="search" href="{{ url_for('opensearch') }}"/>
32+ <link title="{{ instance_name }}" type="application/opensearchdescription+xml" rel="search" href="{{ opensearch_url }}"/>
3333 {% endblock %}
3434 <link rel="shortcut icon" href="{{ url_for('static', filename='img/favicon.png') }}" />
3535</head>
searx/webapp.py+3
@@ -386,6 +386,9 @@ def render(template_name, override_theme=None, **kwargs):
386386
387387 kwargs['proxify'] = proxify if settings.get('result_proxy', {}).get('url') else None
388388
389+ kwargs['opensearch_url'] = url_for('opensearch') + '?' \
390+ + urlencode({'method': kwargs['method'], 'autocomplete': kwargs['autocomplete']})
391+
389392 kwargs['get_result_template'] = get_result_template
390393
391394 kwargs['theme'] = get_current_theme_name(override=override_theme)