summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2021-02-09 12:07:19 +0100
committerAlexandre Flament <alex@al-f.net>2021-02-12 11:10:08 +0100
commitc22d4c764cae6097c463045e86bc81b4becb2545 (patch)
treeaed0a3d557b114179dddc1ff329b0dfbeaec6640
parentd76660463b9001137c092d61a2781464f8345316 (diff)
downloadsearxng-c22d4c764cae6097c463045e86bc81b4becb2545.tar.gz
searxng-c22d4c764cae6097c463045e86bc81b4becb2545.zip
[fix] duckduckgo engine: "!ddg !g" do not redirect to google
* searx understand "!ddg !g time" as : send "!g time" to DDG * !g a DDG bang for Google: DDG return a HTTP redirect to Google This commit adds a the allows_redirect param not to follow HTTP redirect. The DDG engine returns a empty result as before without HTTP redirect.
-rw-r--r--docs/dev/engine_overview.rst1
-rw-r--r--searx/engines/duckduckgo.py8
-rw-r--r--searx/search/processors/online.py4
3 files changed, 12 insertions, 1 deletions
diff --git a/docs/dev/engine_overview.rst b/docs/dev/engine_overview.rst
index 7007e7b99..b51181974 100644
--- a/docs/dev/engine_overview.rst
+++ b/docs/dev/engine_overview.rst
@@ -169,6 +169,7 @@ headers set HTTP header information
data set HTTP data information
cookies set HTTP cookies
verify bool Performing SSL-Validity check
+allow_redirects bool Follow redirects
max_redirects int maximum redirects, hard limit
soft_max_redirects int maximum redirects, soft limit. Record an error but don't stop the engine
raise_for_httperror bool True by default: raise an exception if the HTTP code of response is >= 300
diff --git a/searx/engines/duckduckgo.py b/searx/engines/duckduckgo.py
index 638f1211b..92431b137 100644
--- a/searx/engines/duckduckgo.py
+++ b/searx/engines/duckduckgo.py
@@ -75,12 +75,18 @@ def request(query, params):
params['data']['kl'] = region_code
params['cookies']['kl'] = region_code
- params['data']['df'] = time_range_dict.get(params['time_range'], '')
+ if params['time_range'] in time_range_dict:
+ params['data']['df'] = time_range_dict[params['time_range']]
+
+ params['allow_redirects'] = False
return params
# get response from search-request
def response(resp):
+ if resp.status_code == 303:
+ return []
+
# ping
headers_ping = dict_subset(resp.request.headers, ['User-Agent', 'Accept-Encoding', 'Accept', 'Cookie'])
get(url_ping, headers=headers_ping)
diff --git a/searx/search/processors/online.py b/searx/search/processors/online.py
index 0cc175e1b..df0ab8c21 100644
--- a/searx/search/processors/online.py
+++ b/searx/search/processors/online.py
@@ -73,6 +73,10 @@ class OnlineProcessor(EngineProcessor):
if max_redirects:
request_args['max_redirects'] = max_redirects
+ # allow_redirects
+ if 'allow_redirects' in params:
+ request_args['allow_redirects'] = params['allow_redirects']
+
# soft_max_redirects
soft_max_redirects = params.get('soft_max_redirects', max_redirects or 0)