summaryrefslogtreecommitdiff
path: root/searx/webapp.py
diff options
context:
space:
mode:
authorMohamad Safadieh <me@msafadieh.com>2020-08-09 07:59:49 -0400
committerMohamad Safadieh <me@msafadieh.com>2020-08-09 07:59:49 -0400
commit1ea35605d186272dd69537065acc3161ddb4c7a9 (patch)
treea41a3b505d1fe1d4d83ca91e275e9b76145d4f0e /searx/webapp.py
parent3c45fb7a99c09166c36001d442312363b436b6ac (diff)
Use query params for browser autocomplete
Sending query params over GET seems to be the only way to be able to enable autocomplete in the browser. This commit adds the necessary URL formatting to opensearch.xml. In order to identify queries coming from the URL bar (rather than an AJAX request), which requires a different JSON format and MIME type, the request headers are checked for "X-Requested-With: XMLHttpRequest" which is added by jQuery request.
Diffstat (limited to 'searx/webapp.py')
-rwxr-xr-xsearx/webapp.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/searx/webapp.py b/searx/webapp.py
index 2df96e198..f79525d39 100755
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -790,12 +790,12 @@ def autocompleter():
results.append(raw_text_query.getFullQuery())
# return autocompleter results
- if request.form.get('format') == 'x-suggestions':
- return Response(json.dumps([raw_text_query.query, results]),
+ if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
+ return Response(json.dumps(results),
mimetype='application/json')
- return Response(json.dumps(results),
- mimetype='application/json')
+ return Response(json.dumps([raw_text_query.query, results]),
+ mimetype='application/x-suggestions+json')
@app.route('/preferences', methods=['GET', 'POST'])