From 4d86f0fb959b92e4dfeb141ddd0f6424322d131c Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Sun, 10 Jan 2021 09:50:51 +0100 Subject: [PATCH] Add powershell to PLAIN_TEXT_AGENTS (#273) --- bin/app.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/bin/app.py b/bin/app.py index 638bfbe..17acc03 100644 --- a/bin/app.py +++ b/bin/app.py @@ -73,13 +73,22 @@ app.jinja_loader = jinja2.ChoiceLoader([ LIMITS = Limits() -def is_html_needed(user_agent): +PLAIN_TEXT_AGENTS = [ + "curl", + "httpie", + "lwp-request", + "wget", + "python-requests", + "openbsd ftp", + "powershell", + "fetch", +] + +def _is_html_needed(user_agent): """ Basing on `user_agent`, return whether it needs HTML or ANSI """ - plaintext_clients = [ - 'curl', 'wget', 'fetch', 'httpie', 'lwp-request', 'openbsd ftp', 'python-requests'] - return all([x not in user_agent for x in plaintext_clients]) + return all([x not in user_agent for x in PLAIN_TEXT_AGENTS]) def is_result_a_script(query): return query in [':cht.sh'] @@ -233,7 +242,7 @@ def answer(topic=None): """ user_agent = request.headers.get('User-Agent', '').lower() - html_needed = is_html_needed(user_agent) + html_needed = _is_html_needed(user_agent) options = parse_args(request.args) if topic in ['apple-touch-icon-precomposed.png', 'apple-touch-icon.png', 'apple-touch-icon-120x120-precomposed.png'] \ @@ -276,7 +285,7 @@ def answer(topic=None): if not_allowed: return "429 %s\n" % not_allowed, 429 - html_is_needed = is_html_needed(user_agent) and not is_result_a_script(topic) + html_is_needed = _is_html_needed(user_agent) and not is_result_a_script(topic) if html_is_needed: output_format='html' else: