Skip to content

Commit 4d86f0f

Browse files
committed
Add powershell to PLAIN_TEXT_AGENTS (chubin#273)
1 parent 6f688ef commit 4d86f0f

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

bin/app.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,22 @@ def filter(self, record):
7373

7474
LIMITS = Limits()
7575

76-
def is_html_needed(user_agent):
76+
PLAIN_TEXT_AGENTS = [
77+
"curl",
78+
"httpie",
79+
"lwp-request",
80+
"wget",
81+
"python-requests",
82+
"openbsd ftp",
83+
"powershell",
84+
"fetch",
85+
]
86+
87+
def _is_html_needed(user_agent):
7788
"""
7889
Basing on `user_agent`, return whether it needs HTML or ANSI
7990
"""
80-
plaintext_clients = [
81-
'curl', 'wget', 'fetch', 'httpie', 'lwp-request', 'openbsd ftp', 'python-requests']
82-
return all([x not in user_agent for x in plaintext_clients])
91+
return all([x not in user_agent for x in PLAIN_TEXT_AGENTS])
8392

8493
def is_result_a_script(query):
8594
return query in [':cht.sh']
@@ -233,7 +242,7 @@ def answer(topic=None):
233242
"""
234243

235244
user_agent = request.headers.get('User-Agent', '').lower()
236-
html_needed = is_html_needed(user_agent)
245+
html_needed = _is_html_needed(user_agent)
237246
options = parse_args(request.args)
238247

239248
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):
276285
if not_allowed:
277286
return "429 %s\n" % not_allowed, 429
278287

279-
html_is_needed = is_html_needed(user_agent) and not is_result_a_script(topic)
288+
html_is_needed = _is_html_needed(user_agent) and not is_result_a_script(topic)
280289
if html_is_needed:
281290
output_format='html'
282291
else:

0 commit comments

Comments
 (0)